Example #1
0
 public DocumentMovementsEditModel GetCreateWithoutSendModel()
 {
     var model = new DocumentMovementsEditModel();
     var doctypes = documentMovements_DocTypesDao.LoadAll();
     var folders = DocumentMovementsFoldersDao.LoadAll().Select(x => new IdNameDto { Id = x.Id, Name = x.Name }).ToList();
     folders = folders.OrderBy(x => x.Name).ToList();
     folders.ForEach(x => model.Folders.Add(x));
     model.SelectedDocs = new List<DocumentMovementsSelectedDocsDto>();
     model.RuscountUsers = DocumentMovementsRoleRecordsDao.LoadAll().Select(x => new IdNameDto { Id = x.Id, Name = x.Name }).ToList();
     foreach (var doctype in doctypes)
     {
         model.SelectedDocs.Add(new DocumentMovementsSelectedDocsDto { Type = doctype.Id, TypeName = doctype.Name, Folder = doctype.Folder!=null?doctype.Folder.Id:0 });
     }
     model.SelectedDocs = model.SelectedDocs.OrderBy(x => x.TypeName).ToList();
     return model;
 }
 public ContentResult SaveModelsFromList(DocumentMovementsEditModel[] models)
 {
     DocumentMovementsBl.SaveModelsFromList(models);
     return Content("Ok");
 }
 public ActionResult DocumentMovementsEdit(DocumentMovementsEditModel model)
 {
     model = DocumentMovementsBl.SaveModel(model);
     return View(model);
 }
 public RedirectToRouteResult CreateWithoutSend(DocumentMovementsEditModel model)
 {
     int id = DocumentMovementsBl.SaveCreateWithoutSendModel(model);
     return RedirectToAction("DocumentMovementsEdit", (object) new { id = id });
 }
Example #5
0
 private void SetModel(DocumentMovementsEditModel model)
 {
     DocumentMovements entity = null;
     var doctypes = documentMovements_DocTypesDao.LoadAll();
     var folders = DocumentMovementsFoldersDao.LoadAll().Select(x => new IdNameDto { Id = x.Id, Name = x.Name }).ToList();
     folders = folders.OrderBy(x => x.Name).ToList();
     folders.ForEach(x => model.Folders.Add(x));
     model.SelectedDocs = new List<DocumentMovementsSelectedDocsDto>();
     model.RuscountUsers = DocumentMovementsRoleRecordsDao.LoadAll().Select(x => new IdNameDto { Id = x.Id, Name = x.Name }).ToList();
     if (model.Id > 0)
     {
         entity = DocumentMovementsDao.Load(model.Id);
         if (entity.SendDate.HasValue)
             foreach (var doc in entity.Docs)
             {
                 model.SelectedDocs.Add(new DocumentMovementsSelectedDocsDto { Type = doc.DocType.Id, TypeName = doc.DocType.Name, Folder = doc.DocType.Folder != null ? doc.DocType.Folder.Id : 0, SenderCheck = doc.SenderCheck, SenderCheckDate = doc.SenderCheckDate, RecieverCheck = doc.RecieverCheck, RecieverCheckDate = doc.RecieverCheckDate });
             }
         else
             foreach (var doctype in doctypes)
             {
                 model.SelectedDocs.Add(new DocumentMovementsSelectedDocsDto { Type = doctype.Id, TypeName = doctype.Name, Folder = doctype.Folder != null ? doctype.Folder.Id : 0 });
             }
     }
     else
     {
         entity = CreateNewEntity();
         foreach (var doctype in doctypes)
         {
             model.SelectedDocs.Add(new DocumentMovementsSelectedDocsDto { Type = doctype.Id, TypeName = doctype.Name, Folder=doctype.Folder!=null?doctype.Folder.Id:0 });
         }
     }
     model.Id = entity.Id;
     model.Sender.Id = entity.Sender.Id;
     if (entity.SenderRuscount!=null)
     {
         model.User.Name = entity.SenderRuscount.Name;
     }
     else
     {
         LoadUserData(model.Sender);
     }
     if (CurrentUser.Id == model.Sender.Id) model.IsUserSender = true;
     if (entity.Receiver != null)
     {
         if (entity.ReceiverRuscount != null)
         {
             model.Receiver.Id = (CurrentUser.UserRole& UserRole.PersonnelManager)>0?CurrentUser.Id:entity.Receiver.Id;
             model.Receiver.Name = entity.ReceiverRuscount.Name;
         }
         else
         {
             model.Receiver.Id = entity.Receiver.Id;
             LoadUserData(model.Receiver);
         }
         if (CurrentUser.Id == model.Receiver.Id) model.IsUserReceiver = true;
     }
     if (entity.User != null)
     {
         model.User.Id = entity.User.Id;
         LoadUserData(model.User);
     }
     if (!entity.SendDate.HasValue)
     {
         var docs = entity.Docs.Select(x => new DocumentMovementsSelectedDocsDto().FromDomain(x)).ToList();
         docs.ForEach(x =>
         {
             var doc = model.SelectedDocs.First(y => y.Type == x.Type);
             doc.RecieverCheck = x.RecieverCheck;
             doc.RecieverCheckDate = x.RecieverCheckDate;
             doc.SenderCheck = x.SenderCheck;
             doc.SenderCheckDate = x.SenderCheckDate;
         });
     }
     model.SenderAccept = entity.SendDate.HasValue;
     model.ReceiverAccept = entity.ReceiverCheckDate.HasValue;
     model.SendDate = entity.SendDate;
     model.CreateDate = entity.CreateDate;
     model.Descript = entity.Descript;
     model.SelectedDocs = model.SelectedDocs.OrderBy(x => x.TypeName).ToList();
     if ((CurrentUser.UserRole & (UserRole.Manager | UserRole.Secretary | UserRole.ConsultantPersonnel)) > 0)
         model.IsUserFromBank = true;
 }
Example #6
0
 public void SaveModelsFromList(DocumentMovementsEditModel[] models)
 {
     if (models == null || models.Length==0) return;
     for (int i = 0; i < models.Length; i++)
     {
         var tmp = models[i];
         var movement = DocumentMovementsDao.Load(tmp.Id);
         foreach (var doc in tmp.SelectedDocs)
         {
             var current=movement.Docs.Where(x => x.DocType.Id == doc.Type);
             if (current != null && current.Any())
             {
                 var d = current.First();
                 if (d.RecieverCheck != doc.RecieverCheck)
                 {
                     d.RecieverCheck = doc.RecieverCheck;
                     d.RecieverCheckDate = DateTime.Now;
                 }
             }
         }
         if (!movement.ReceiverCheckDate.HasValue && tmp.ReceiverAccept)
         {
             movement.ReceiverCheckDate = DateTime.Now;
         }
         if (movement.ReceiverCheckDate.HasValue) movement.StatusId = 3;
         DocumentMovementsDao.SaveAndFlush(movement);
     }
 }
Example #7
0
 public DocumentMovementsEditModel SaveModel(DocumentMovementsEditModel model)
 {
     DocumentMovements entity = null;
     if (model.Id > 0)
     {
         entity = DocumentMovementsDao.Load(model.Id);
     }
     else
     {
         entity = CreateNewEntity();
     }
     var newdocs = model.SelectedDocs.Where(x =>x.SenderCheck && !entity.Docs.Any(y => y.DocType.Id == x.Type));
     foreach (var newdoc in newdocs)
         entity.Docs.Add(new DocumentMovements_SelectedDocs { DocType = DocumentMovements_DocTypesDao.Load(newdoc.Type), Movement = entity });
     if (entity.Sender.Id == CurrentUser.Id)
     {
         if (!entity.SendDate.HasValue)
         {
             if (entity.Id == 0)
             {
                 entity.User = UserDao.Load(model.User.Id);
                 if ((CurrentUser.UserRole & UserRole.PersonnelManager) > 0)
                 {
                     entity.Direction = 1;
                     var sender = DocumentMovementsRoleRecordsDao.Load(model.SenderRuscount);
                     entity.SenderRuscount = sender;
                     entity.Receiver = UserDao.Load(model.Receiver.Id);
                 }
                 else
                 {
                     entity.Direction = 2;
                     var receiver = DocumentMovementsRoleRecordsDao.Load(model.Receiver.Id);
                     entity.Receiver = receiver.User;
                     entity.ReceiverRuscount = receiver;
                 }
             }
             entity.Descript = model.Descript;
         }
         if (model.SenderAccept && !entity.SendDate.HasValue)
         {
             entity.SendDate = DateTime.Now;
         }
         foreach (var doc in entity.Docs)
         {
             var editeddoc = model.SelectedDocs.First(x => x.Type == doc.DocType.Id);
             if (editeddoc == null) continue;
             if (doc.SenderCheck != editeddoc.SenderCheck) doc.SenderCheckDate = editeddoc.SenderCheck ? DateTime.Now : new DateTime?();
             doc.SenderCheck = editeddoc.SenderCheck;
         }
     }
     if (entity.Receiver != null && entity.Receiver.Id == CurrentUser.Id)
     {
         if (model.ReceiverAccept && !entity.ReceiverCheckDate.HasValue)
         {
             entity.ReceiverCheckDate = DateTime.Now;
         }
         foreach (var doc in entity.Docs)
         {
             var editeddoc = model.SelectedDocs.First(x => x.Type == doc.DocType.Id);
             if (editeddoc == null) continue;
             if (doc.RecieverCheck != editeddoc.RecieverCheck) doc.RecieverCheckDate = editeddoc.RecieverCheck ? DateTime.Now : new DateTime?();
             doc.RecieverCheck = editeddoc.RecieverCheck;
         }
     }
     entity.StatusId = 1;
     if (entity.SendDate.HasValue) entity.StatusId = 2;
     if (entity.ReceiverCheckDate.HasValue) entity.StatusId = 3;
     DocumentMovementsDao.SaveAndFlush(entity);
     DocumentMovementsEditModel newmodel = new DocumentMovementsEditModel();
     newmodel.Id = entity.Id;
     SetModel(newmodel);
     return newmodel;
 }
Example #8
0
 public int SaveCreateWithoutSendModel(DocumentMovementsEditModel model)
 {
     DocumentMovements entity = new DocumentMovements();
     entity.SendDate = DateTime.Now;
     entity.ReceiverCheckDate = DateTime.Now;
     entity.CreateDate = DateTime.Now;
     entity.Direction = 2;
     entity.StatusId = 3;
     entity.Receiver = UserDao.Load(10);
     entity.ReceiverRuscount = DocumentMovementsRoleRecordsDao.Load(model.SenderRuscount);
     entity.Sender = UserDao.Load(model.User.Id);
     entity.Descript = model.Descript;
     entity.User = entity.Sender;
     entity.Docs = new List<DocumentMovements_SelectedDocs>();
     var newdocs = model.SelectedDocs.Where(x => x.RecieverCheck).ToList();
     foreach (var newdoc in newdocs)
         entity.Docs.Add(new DocumentMovements_SelectedDocs { DocType = DocumentMovements_DocTypesDao.Load(newdoc.Type), Movement = entity, RecieverCheck= true, SenderCheck = true, RecieverCheckDate=DateTime.Now, SenderCheckDate = DateTime.Now });
     DocumentMovementsDao.SaveAndFlush(entity);
     return entity.Id;
 }
Example #9
0
 public DocumentMovementsEditModel GetEditModel(int Id)
 {
     DocumentMovementsEditModel model = new DocumentMovementsEditModel();
     model.Id = Id;
     SetModel(model);
     return model;
 }