Exemplo n.º 1
0
 protected int? SaveAttachment(int entityId, int id, UploadFileDto dto, RequestAttachmentTypeEnum type, out string attachment)
 {
     attachment = string.Empty;
     if (dto == null)
         return new int?();
     RequestAttachment attach = id != 0 ?
        RequestAttachmentDao.Get(id) :
        new RequestAttachment
        {
            RequestId = entityId,
            RequestType = (int)type,
            CreatorRole = RoleDao.Load((int)CurrentUser.UserRole),
        };
     if (id == 0)
     {
         RequestAttachment existingAttach = RequestAttachmentDao.FindByRequestIdAndTypeId(entityId, type);
         if (existingAttach != null)
         {
             Log.InfoFormat("Файл уже существует", entityId, type, existingAttach.Id);
             attach = existingAttach;
         }
     }
     attach.DateCreated = DateTime.Now;
     attach.UncompressContext = dto.Context;
     attach.ContextType = dto.ContextType;
     attach.FileName = dto.FileName;
     attach.CreatorRole = RoleDao.Load((int)CurrentUser.UserRole);
     RequestAttachmentDao.SaveAndFlush(attach);
     attachment = attach.FileName;
     if (type == RequestAttachmentTypeEnum.StaffMovements)
     {
         var doc=StaffMovementsDocsDao.Load(entityId);
         doc.Attachment = attach;
         StaffMovementsDocsDao.SaveAndFlush(doc);
     }
     return attach.Id;
 }
Exemplo n.º 2
0
        public RequestAttachmentsModel GetHelpPersonnelBillingAttachmentsModel(HelpPersonnelBillingRequest entity, RequestAttachmentTypeEnum typeId)
        {
            if(entity.Id == 0)
            {
                return new RequestAttachmentsModel
                           {
                               AttachmentRequestId = 0,
                               AttachmentRequestTypeId = (int) typeId,
                               Attachments = new List<RequestAttachmentModel>(),
                               IsAddAvailable = false
                           };
            }

            //открыто для создающего и отвечающих, кроме просмотровой роли
            bool isAddAvailable = (!entity.SendDate.HasValue && (entity.Creator.Id == CurrentUser.Id)) ||
                ((entity.BeginWorkDate.HasValue && !entity.EndWorkDate.HasValue && (AuthenticationService.CurrentUser.UserRole != UserRole.OutsourcingManager) && (AuthenticationService.CurrentUser.UserRole != UserRole.Estimator)));

            List<RequestAttachment> list = RequestAttachmentDao.FindManyByRequestIdAndTypeId(entity.Id, typeId).ToList();
            RequestAttachmentsModel model = new RequestAttachmentsModel
            {
                AttachmentRequestId = entity.Id,
                AttachmentRequestTypeId = (int)typeId,
                IsAddAvailable = isAddAvailable,
                Attachments = new List<RequestAttachmentModel>()
            };
            model.Attachments = list.ConvertAll(x =>
                            new RequestAttachmentModel
                            {
                                Attachment = x.FileName,
                                AttachmentId = x.Id,
                                Description = x.Description,
                                IsDeleteAvailable = ((x.CreatorUserRole & CurrentUser.UserRole) > 0 || AuthenticationService.CurrentUser.UserRole == UserRole.ConsultantOutsourcing) && isAddAvailable,
                            });
            return model;
        }
Exemplo n.º 3
0
 protected void SetAttachmentToModel(IAttachment model, int id, RequestAttachmentTypeEnum type)
 {
     if (id == 0)
         return;
     RequestAttachment attach = RequestAttachmentDao.FindByRequestIdAndTypeId(id, type);
     if (attach == null)
         return;
     model.AttachmentId = attach.Id;
     model.Attachment = attach.FileName;
 }
Exemplo n.º 4
0
 public RequestAttachmentsModel GetBillingAttachmentsModel(int id,RequestAttachmentTypeEnum type)
 {
     switch (type)
     {
         case RequestAttachmentTypeEnum.HelpPersonnelBillingRequest:
             return GetHelpPersonnelBillingAttachmentsModel(HelpPersonnelBillingRequestDao.Load(id),type);
         default:
             throw new ValidationException(string.Format(StrInvalidAttachmentType,type));
     }
 }