Beispiel #1
0
 public void FieldSave(OBK_CertificateReference oldModel, OBK_CertificateReference newModel, Guid userId)
 {
     if ((newModel.Number == null && oldModel.Number != null) || (newModel.Number != null && !newModel.Number.Equals(oldModel.Number)))
     {
         LogChange(nameof(newModel.Number), newModel.Number.ToString(), userId,
                   newModel.Id, propertyNameRuList.First(x => x.Key == nameof(newModel.Number)).Value);
     }
     if ((newModel.CertificateNumber == null && oldModel.CertificateNumber != null) ||
         (newModel.CertificateNumber != null && !newModel.CertificateNumber.Equals(oldModel.CertificateNumber)))
     {
         LogChange(nameof(newModel.CertificateNumber), newModel.CertificateNumber.ToString(), userId,
                   newModel.Id, propertyNameRuList.First(x => x.Key == nameof(newModel.CertificateNumber)).Value);
     }
     if ((newModel.StartDate == null && oldModel.StartDate != null) ||
         (newModel.StartDate != null && !newModel.StartDate.Equals(oldModel.StartDate)))
     {
         LogChange(nameof(newModel.StartDate), newModel.StartDate.ToString(), userId,
                   newModel.Id, propertyNameRuList.First(x => x.Key == nameof(newModel.StartDate)).Value);
     }
     if ((newModel.EndDate == null && oldModel.EndDate != null) ||
         (newModel.EndDate != null && !newModel.EndDate.Equals(oldModel.EndDate)))
     {
         LogChange(nameof(newModel.EndDate), newModel.EndDate.ToString(), userId,
                   newModel.Id, propertyNameRuList.First(x => x.Key == nameof(newModel.EndDate)).Value);
     }
     if ((newModel.CertificateOrganization == null && oldModel.CertificateOrganization != null) ||
         (newModel.CertificateOrganization != null && !newModel.CertificateOrganization.Equals(oldModel.CertificateOrganization)))
     {
         LogChange(nameof(newModel.CertificateOrganization), newModel.CertificateOrganization.ToString(), userId,
                   newModel.Id, propertyNameRuList.First(x => x.Key == nameof(newModel.CertificateOrganization)).Value);
     }
     if (!newModel.CertificateTypeId.Equals(oldModel.CertificateTypeId))
     {
         LogChange(nameof(newModel.CertificateTypeId), newModel.CertificateTypeId.ToString(), userId,
                   newModel.Id, propertyNameRuList.First(x => x.Key == nameof(newModel.CertificateTypeId)).Value);
     }
     if ((newModel.LastInspection == null && oldModel.LastInspection != null) ||
         (newModel.LastInspection != null && !newModel.LastInspection.Equals(oldModel.LastInspection)))
     {
         LogChange(nameof(newModel.LastInspection), newModel.LastInspection.ToString(), userId,
                   newModel.Id, propertyNameRuList.First(x => x.Key == nameof(newModel.LastInspection)).Value);
     }
     if ((newModel.CertificateCountryId == null && oldModel.CertificateCountryId != null) ||
         (newModel.CertificateCountryId != null && !newModel.CertificateCountryId.Equals(oldModel.CertificateCountryId)))
     {
         LogChange(nameof(newModel.CertificateCountryId), newModel.CertificateCountryId.ToString(), userId,
                   newModel.Id, propertyNameRuList.First(x => x.Key == nameof(newModel.CertificateCountryId)).Value);
     }
     if ((newModel.CertificateValidityTypeId == null && oldModel.CertificateValidityTypeId != null) ||
         (newModel.CertificateValidityTypeId != null && !newModel.CertificateValidityTypeId.Equals(oldModel.CertificateValidityTypeId)))
     {
         LogChange(nameof(newModel.CertificateValidityTypeId), newModel.CertificateValidityTypeId.ToString(), userId,
                   newModel.Id, propertyNameRuList.First(x => x.Key == nameof(newModel.CertificateValidityTypeId)).Value);
     }
 }
Beispiel #2
0
        public void UpdateCertificates()
        {
            var list = AppContext.OBK_CertificateReference.Include(o => o.OBK_CertificateValidityType).ToList();

            foreach (var obj in list)
            {
                if (obj.EndDate < DateTime.Now && !"Recalled".Equals(obj.OBK_CertificateValidityType.Code))
                {
                    OBK_CertificateReference d = AppContext.OBK_CertificateReference.First(o => o.Id == obj.Id);
                    d.OBK_CertificateValidityType = AppContext.OBK_CertificateValidityType.First(o => o.Code == "Passive");
                    AppContext.SaveChanges();
                }
            }
        }
Beispiel #3
0
        public ActionResult DicDestroy([DataSourceRequest] DataSourceRequest request, OBKCertificateReferenceModel dictionary,
                                       string type)
        {
            if (dictionary != null)
            {
                OBK_CertificateReference d = db.OBK_CertificateReference.First(o => o.Id == dictionary.Id);
                //Document doc = db.Documents.First(o => o.Id == d.DocumentId);

                db.OBK_CertificateReference.Remove(d);
                db.SaveChanges();
            }

            return(Json(new[] { dictionary }.ToDataSourceResult(request, ModelState)));
        }
Beispiel #4
0
 public OBK_CertificateReference CopyObject(OBK_CertificateReference old)
 {
     return(new OBK_CertificateReference
     {
         Id = old.Id,
         Number = old.Number,
         CertificateNumber = old.CertificateNumber,
         StartDate = old.StartDate,
         EndDate = old.EndDate,
         CertificateCountryId = old.CertificateCountryId,
         CertificateOrganization = old.CertificateOrganization,
         CertificateTypeId = old.CertificateTypeId,
         CertificateValidityTypeId = old.CertificateValidityTypeId,
         LastInspection = old.LastInspection
     });
 }
Beispiel #5
0
        public ActionResult DocumentRead(Guid id)
        {
            OBK_CertificateReference reference = db.OBK_CertificateReference.Find(id);
            OBKCertificateFileModel  fileModel = new OBKCertificateFileModel();

            if (reference != null && reference.AttachPath != null)
            {
                fileModel.AttachPath  = reference.AttachPath;
                fileModel.AttachFiles = UploadHelper.GetFilesInfo(fileModel.AttachPath.ToString(), false);
            }
            else
            {
                fileModel.AttachPath  = FileHelper.GetObjectPathRoot();
                fileModel.AttachFiles = UploadHelper.GetFilesInfo(fileModel.AttachPath.ToString(), false);
            }

            return(Content(JsonConvert.SerializeObject(fileModel, Formatting.Indented, new JsonSerializerSettings()
            {
                DateFormatString = "dd.MM.yyyy HH:mm"
            })));
        }
Beispiel #6
0
        public ActionResult Recall([DataSourceRequest] DataSourceRequest request, Guid?Id)
        {
            OBK_CertificateReference obj = db.OBK_CertificateReference.FirstOrDefault(o => o.Id == Id);
            var oldCopy = fieldSaver.CopyObject(obj);

            if (obj != null)
            {
                obj.OBK_CertificateValidityType = db.OBK_CertificateValidityType.First(o => o.Code == "Recalled");
                db.SaveChanges();

                fieldSaver.FieldSave(oldCopy, obj, UserHelper.GetCurrentEmployee().Id);

                return(Json(new
                {
                    success = true
                }));
            }

            return(Json(new
            {
                success = false
            }));
        }
Beispiel #7
0
        public ActionResult DicCreate([DataSourceRequest] DataSourceRequest request, OBKCertificateReferenceModel dictionary)
        {
            if (dictionary != null && ModelState.IsValid)
            {
                OBK_CertificateReference d = new OBK_CertificateReference()
                {
                    Id                      = (Guid)dictionary.Id,
                    Number                  = dictionary.Number,
                    CertificateNumber       = dictionary.CertificateNumber,
                    StartDate               = dictionary.StartDate,
                    EndDate                 = dictionary.EndDate,
                    CertificateCountryId    = dictionary.CertificateCountryId,
                    CertificateOrganization = dictionary.CertificateOrganization,
                    CertificateProducer     = dictionary.CertificateProducer,
                    CertificateTypeId       = dictionary.CertificateTypeId,
                    LastInspection          = dictionary.LastInspection,
                    AttachPath              = dictionary.AttachPath,
                    CreateDate              = DateTime.Now,
                    ExpertOrganization      = UserHelper.GetCurrentEmployee().OrganizationId
                };
                if (dictionary.EndDate >= DateTime.Now)
                {
                    OBK_CertificateValidityType t = db.OBK_CertificateValidityType.First(o => o.Code == "active");
                    d.OBK_CertificateValidityType = t;
                }
                else
                {
                    OBK_CertificateValidityType t = db.OBK_CertificateValidityType.First(o => o.Code == "passive");
                    d.OBK_CertificateValidityType = t;
                }

                db.OBK_CertificateReference.Add(d);
                db.SaveChanges();

                fieldSaver.FieldSave(new OBK_CertificateReference(), d, UserHelper.GetCurrentEmployee().Id);

                List <UploadInitialFile> physicalfiles = UploadHelper.GetFilesInfo(dictionary.AttachPath.ToString(), false);

                List <FileLink> oldList = db.FileLinks.Where(o => o.DocumentId == dictionary.Id).ToList();

                foreach (var file in physicalfiles)
                {
                    if (!oldList.Any(o => o.FileName == file.name))
                    {
                        FileLink dbFile = new FileLink
                        {
                            Id         = Guid.NewGuid(),
                            FileName   = file.name,
                            CreateDate = DateTime.Now,
                            DocumentId = dictionary.Id,
                            OwnerId    = UserHelper.GetCurrentEmployee().Id,
                            IsDeleted  = false,
                        };
                        db.FileLinks.Add(dbFile);
                        fieldSaver.LogChange("FileLinks", dbFile.FileName, UserHelper.GetCurrentEmployee().Id,
                                             dictionary.Id, "добавлен");
                    }
                }
                db.SaveChanges();
                dictionary.Id = d.Id;
            }

            return(Json(new[] { dictionary }.ToDataSourceResult(request, ModelState)));
        }