public Response <DocumentPerformResponseModel> CreateResponse(DocumentPerformResponseModel createModel)
        {
            try
            {
                using (var unitOfWork = new UnitOfWork())
                {
                    var existed = unitOfWork.GetRepository <QH_DocumentPerform_User>().Get(d => d.DocumentPerformId == createModel.DocumentPerformId && d.UserId == createModel.UserId);
                    if (existed != null)
                    {
                        return(new Response <DocumentPerformResponseModel>(0, "Bạn đã thống nhất rồi!", null));
                    }
                    QH_DocumentPerform_User entity = new QH_DocumentPerform_User();
                    Ultis.TransferValues(entity, createModel);
                    unitOfWork.GetRepository <QH_DocumentPerform_User>().Add(entity);
                    //update status
                    //turn off notif
                    var notif = unitOfWork.GetRepository <TaskMessage>().Get(c => c.UserId == createModel.UserId && c.RelatedId == createModel.DocumentPerformId);
                    if (notif != null)
                    {
                        notif.Status = 1;
                        unitOfWork.GetRepository <TaskMessage>().Update(notif);
                    }

                    if (unitOfWork.Save() >= 1)
                    {
                        return(GetResponse(createModel.UserId, createModel.DocumentPerformId));
                    }
                    return(new Response <DocumentPerformResponseModel>(0, "", null));
                }
            }
            catch (Exception ex)
            {
                return(new Response <DocumentPerformResponseModel>(-1, ex.ToString(), null));
            }
        }
 public Response <DocumentPerformModel> Update(int Id, DocumentPerformUpdateModel updateModel)
 {
     try
     {
         using (var unitOfWork = new UnitOfWork())
         {
             var entity = unitOfWork.GetRepository <DocumentPerform>().GetById(Id);
             if (entity != null)
             {
                 Ultis.TransferValues(entity, updateModel);
                 entity.UpdatedOnDate = DateTime.Now;
                 unitOfWork.GetRepository <DocumentPerform>().Update(entity);
                 if (unitOfWork.Save() >= 1)
                 {
                     return(GetById(entity.PerformId));
                 }
                 return(new Response <DocumentPerformModel>(0, "Saving data not successful!", null));
             }
             return(new Response <DocumentPerformModel>(0, "Id is not valid", null));
         }
     }
     catch (Exception ex)
     {
         return(new Response <DocumentPerformModel>(-1, ex.ToString(), null));
     }
 }
Exemple #3
0
 public Response <InternalDocumentModel> Update(int Id, InternalDocumentUpdateModel userModel)
 {
     try
     {
         using (var unitOfWork = new UnitOfWork())
         {
             var entity = unitOfWork.GetRepository <InternalDocument>().GetById(Id);
             if (entity != null)
             {
                 Ultis.TransferValues(entity, userModel);
                 unitOfWork.GetRepository <InternalDocument>().Update(entity);
                 if (unitOfWork.Save() >= 1)
                 {
                     return(GetById(entity.InternalDocumentId));
                 }
                 return(new Response <InternalDocumentModel>(0, "Lưu thông tin không thành công", null));
             }
             return(new Response <InternalDocumentModel>(0, "Tài liệu không tồn tại", null));
         }
     }
     catch (Exception ex)
     {
         return(new Response <InternalDocumentModel>(-1, ex.ToString(), null));
     }
 }
Exemple #4
0
 public Response <BusinessPartnerModel> Update(int Id, BusinessPartnerUpdateModel updateModel)
 {
     try
     {
         using (var unitOfWork = new UnitOfWork())
         {
             var dir = unitOfWork.GetRepository <BusinessPartner>().GetById(Id);
             if (dir != null)
             {
                 Ultis.TransferValues(dir, updateModel);
                 unitOfWork.GetRepository <BusinessPartner>().Update(dir);
                 if (unitOfWork.Save() >= 1)
                 {
                     return(GetById(dir.PartnerId));
                 }
                 return(new Response <BusinessPartnerModel>(0, "Lưu thông tin không thành công!", null));
             }
             else
             {
                 return(new Response <BusinessPartnerModel>(0, "Không tìm thấy phòng ban", null));
             }
         }
     }
     catch (Exception ex)
     {
         return(new Response <BusinessPartnerModel>(-1, ex.ToString(), null));
     }
 }
Exemple #5
0
 public Response <ReceivedDocumentModel> Update(int Id, ReceivedDocumentUpdateModel updateModel)
 {
     try
     {
         using (var unitOfWork = new UnitOfWork())
         {
             var entity = unitOfWork.GetRepository <ReceivedDocument>().GetById(Id);
             if (entity != null)
             {
                 Ultis.TransferValues(entity, updateModel);
                 entity.LastModifiedOnDate = DateTime.Now;
                 unitOfWork.GetRepository <ReceivedDocument>().Update(entity);
                 if (unitOfWork.Save() >= 1)
                 {
                     return(GetById(entity.ReceivedDocumentId));
                 }
                 return(new Response <ReceivedDocumentModel>(0, "Lưu thông tin không thành công", null));
             }
             return(new Response <ReceivedDocumentModel>(0, "Tài liệu không tồn tại", null));
         }
     }
     catch (Exception ex)
     {
         return(new Response <ReceivedDocumentModel>(-1, ex.ToString(), null));
     }
 }
Exemple #6
0
 public Response <DocumentModel> Update(int Id, DocumentUpdateModel updateModel)
 {
     try
     {
         using (var unitOfWork = new UnitOfWork())
         {
             var doc = unitOfWork.GetRepository <Document>().GetById(Id);
             if (doc != null)
             {
                 Ultis.TransferValues(doc, updateModel);
                 unitOfWork.GetRepository <Document>().Update(doc);
                 if (unitOfWork.Save() >= 1)
                 {
                     return(GetById(doc.DocumentId));
                 }
                 return(new Response <DocumentModel>(0, "Lưu thông tin không thành công!", null));
             }
             else
             {
                 return(new Response <DocumentModel>(0, "Không tìm thấy tài liệu", null));
             }
         }
     }
     catch (Exception ex)
     {
         return(new Response <DocumentModel>(-1, ex.ToString(), null));
     }
 }
 public Response <DirectoryModel> Update(int Id, DirectoryUpdateModel updateModel)
 {
     try
     {
         using (var unitOfWork = new UnitOfWork())
         {
             var dir = unitOfWork.GetRepository <Directory>().GetById(Id);
             if (dir != null)
             {
                 Ultis.TransferValues(dir, updateModel);
                 dir.Name                 = updateModel.Name;
                 dir.ParentId             = updateModel.ParentId;
                 dir.LastModifiedByUserId = updateModel.LastModifiedByUserId;
                 dir.LastModifiedOnDate   = DateTime.Now;
                 unitOfWork.GetRepository <Directory>().Update(dir);
                 if (unitOfWork.Save() >= 1)
                 {
                     return(GetById(dir.DirectoryId));
                 }
                 return(new Response <DirectoryModel>(0, "Lưu thông tin không thành công!", null));
             }
             else
             {
                 return(new Response <DirectoryModel>(0, "Không tìm thấy thư mục", null));
             }
         }
     }
     catch (Exception ex)
     {
         return(new Response <DirectoryModel>(-1, ex.ToString(), null));
     }
 }
 public Response <DocumentConfirmModel> Create(DocumentConfirmCreateModel createModel)
 {
     try
     {
         using (var unitOfWork = new UnitOfWork())
         {
             DocumentConfirm entity = new DocumentConfirm();
             Ultis.TransferValues(entity, createModel);
             entity.CreatedOnDate = DateTime.Now;
             entity.UpdatedOnDate = DateTime.Now;
             var last = unitOfWork.GetRepository <DocumentConfirm>().GetAll().OrderByDescending(u => u.ConfirmId).FirstOrDefault();
             if (last != null)
             {
                 entity.ConfirmId = last.ConfirmId + 1;
             }
             else
             {
                 entity.ConfirmId = 1;
             }
             unitOfWork.GetRepository <DocumentConfirm>().Add(entity);
             TaskMessage message = new TaskMessage
             {
                 CreatedByUserId = createModel.CreatedByUserId,
                 Deadline        = createModel.FinishedOnDate,
                 TaskType        = (int)TaskType.CONFIRM,
                 Title           = createModel.Name,
                 UserId          = createModel.UserId,
                 CreatedOnDate   = DateTime.Now,
                 RelatedId       = entity.ConfirmId,
                 ModuleId        = createModel.ModuleId
             };
             unitOfWork.GetRepository <TaskMessage>().Add(message);
             //
             var tmp = unitOfWork.GetRepository <DocumentProcess>().Get(d => d.Id == createModel.ProcessId && d.TaskType == (int)TaskType.CONFIRM);
             if (tmp == null)
             {
                 return(new Response <DocumentConfirmModel>(0, "Bạn chưa tạo tiến trình xử lý cho tài liệu này", null));
             }
             tmp.Status    = (int)DocumentProcessStatus.INPROCESS;
             tmp.RelatedId = entity.ConfirmId;
             unitOfWork.GetRepository <DocumentProcess>().Update(tmp);
             //
             if (unitOfWork.Save() >= 1)
             {
                 return(GetById(entity.ConfirmId));
             }
             return(new Response <DocumentConfirmModel>(0, "Saving data not successful!", null));
         }
     }
     catch (Exception ex)
     {
         return(new Response <DocumentConfirmModel>(-1, ex.ToString(), null));
     }
 }
 public Response <DocumentConfirmResponseModel> CreateResponse(DocumentConfirmResponseModel createModel)
 {
     try
     {
         using (var unitOfWork = new UnitOfWork())
         {
             var existed = unitOfWork.GetRepository <QH_DocumentConfirm_User>().Get(d => d.DocumentConfirmId == createModel.DocumentConfirmId && d.UserId == createModel.UserId);
             if (existed != null)
             {
                 return(new Response <DocumentConfirmResponseModel>(0, "Bạn đã xác nhận rồi!", null));
             }
             QH_DocumentConfirm_User entity = new QH_DocumentConfirm_User();
             Ultis.TransferValues(entity, createModel);
             unitOfWork.GetRepository <QH_DocumentConfirm_User>().Add(entity);
             var confirm = unitOfWork.GetRepository <DocumentConfirm>().GetById(createModel.DocumentConfirmId);
             if (confirm != null)
             {
                 TaskMessage taskMessage = new TaskMessage
                 {
                     Deadline        = DateTime.Now.AddDays(3),
                     CreatedOnDate   = DateTime.Now,
                     CreatedByUserId = createModel.UserId,
                     UserId          = confirm.CreatedByUserId,
                     IsMyTask        = true,
                     ModuleId        = confirm.ModuleId,
                     RelatedId       = confirm.ConfirmId,
                     Status          = 0,
                     TaskType        = (int)TaskType.CONFIRM,
                     Title           = "Tham khảo phê duyệt " + confirm.Name
                 };
                 unitOfWork.GetRepository <TaskMessage>().Add(taskMessage);
                 if (unitOfWork.Save() >= 1)
                 {
                     return(new Response <DocumentConfirmResponseModel>(1, "", Ultis.ConvertSameData <DocumentConfirmResponseModel>(entity)));
                 }
                 return(new Response <DocumentConfirmResponseModel>(0, "", null));
             }
             return(new Response <DocumentConfirmResponseModel>(0, "", null));
         }
     }
     catch (Exception ex)
     {
         return(new Response <DocumentConfirmResponseModel>(-1, ex.ToString(), null));
     }
 }