optimize admin::attachments controller

move lots of code from controller into model