public ArchivedDiary ToBase() { ArchivedDiary diary = new ArchivedDiary(); diary.Id = this.Id; diary.Number = this.Number; diary.LetterNumber = this.LetterNumber; diary.LetterDate = this.LetterDate.ToUniversalTime(); diary.AcceptanceDateAndTime = this.AcceptanceDateAndTime; diary.Contractor = this.Contractor; diary.Client = this.Client; diary.ClientMobile = this.ClientMobile; diary.Comment = this.Comment; diary.RequestDate = this.RequestDate.ToUniversalTime(); diary.RequestAcceptedBy = this.RequestAcceptedBy; diary.ProtocolIssuedDate = this.ProtocolIssuedDate; diary.ProtocolTester = this.ProtocolTester; diary.ProtocolLabLeader = this.ProtocolLabLeader; diary.Remark = this.Remark; diary.RequestTestingPeriod = this.RequestTestingPeriod; diary.ArchivedProducts = this.ArchivedProducts; diary.ArchivedProtocolResults = this.ArchivedProtocolResults; diary.ArchivedProtocolRemarks = this.ArchivedProtocolRemarks; diary.AcreditationRegisteredDate = this.AcreditationRegisteredDate; diary.AcreditationValidDate = this.AcreditationValidToDate; return(diary); }
public ArchivedDiaryW(ArchivedDiary diary) { Id = diary.Id; Number = diary.Number; LetterNumber = diary.LetterNumber; LetterDate = diary.LetterDate.ToLocalTime(); AcceptanceDateAndTime = diary.AcceptanceDateAndTime; Contractor = diary.Contractor; Client = diary.Client; ClientMobile = diary.ClientMobile; Comment = diary.Comment; RequestDate = diary.RequestDate.ToLocalTime(); RequestAcceptedBy = diary.RequestAcceptedBy; ProtocolIssuedDate = diary.ProtocolIssuedDate; ProtocolTester = diary.ProtocolTester; ProtocolLabLeader = diary.ProtocolLabLeader; Remark = diary.Remark; RequestTestingPeriod = diary.RequestTestingPeriod; AcreditationRegisteredDate = diary.AcreditationRegisteredDate ?? DateTime.Now; AcreditationValidToDate = diary.AcreditationValidDate ?? DateTime.Now; ArchivedProducts = diary.ArchivedProducts; ArchivedProtocolResults = diary.ArchivedProtocolResults; ArchivedProtocolRemarks = diary.ArchivedProtocolRemarks; }
public ArchivedProtocol(ArchivedDiary adiary) { ArchivedDiary = adiary; DiaryId = adiary.Id; IssuedDate = adiary.ProtocolIssuedDate; ProtocolResults = adiary.ArchivedProtocolResults; Tester = adiary.ProtocolTester; LabLeader = adiary.ProtocolLabLeader; }
public ArchivedRequest(ArchivedDiary adiary) { this.DiaryId = adiary.Id; this.Date = adiary.RequestDate; this.AcceptedBy = adiary.RequestAcceptedBy; this.IsAccepted = true; this.TestingPeriod = adiary.RequestTestingPeriod ?? 0; this.Diary = adiary; }
public ActionResponse ArchiveDiary(Guid diaryId) { var res = new ActionResponse(); try { var diaryW = Db.Diaries.Where(x => x.Id == diaryId).Select(DiaryMappings.ToDiaryW).FirstOrDefault(); var archivedDiary = new ArchivedDiary(); archivedDiary.Id = Guid.NewGuid(); archivedDiary.Number = diaryW.Number; archivedDiary.AcceptanceDateAndTime = diaryW.AcceptanceDateAndTime; archivedDiary.LetterNumber = diaryW.LetterNumber?.ToString(); archivedDiary.LetterDate = diaryW.LetterDate; archivedDiary.Contractor = diaryW.Contractor; archivedDiary.Client = diaryW.Client.Name; archivedDiary.ClientMobile = diaryW.Client.Mobile; archivedDiary.Comment = diaryW.Comment; var meta = Db.AcreditationMetas.First(); archivedDiary.AcreditationRegisteredDate = meta.Registered; archivedDiary.AcreditationValidDate = meta.ValidTo; var request = diaryW.Request; archivedDiary.RequestDate = request.Date; archivedDiary.RequestAcceptedBy = request.User.FirstName.Substring(0, 1) + ". " + request.User.LastName; archivedDiary.RequestTestingPeriod = request.TestingPeriod; archivedDiary.Remark = diaryW.Remark; var protocol = request.Protocols.First(); archivedDiary.ProtocolIssuedDate = protocol.IssuedDate; archivedDiary.ProtocolTester = protocol.Tester; archivedDiary.ProtocolLabLeader = protocol.LabLeader; foreach (var remark in protocol.ProtocolsRemarks) { var aremark = new ArchivedProtocolRemark() { Id = Guid.NewGuid(), ArchivedDiaryId = archivedDiary.Id, Remark = remark.Remark.Text, AcredetationLevel = remark.AcredetationLevel.Level, Number = remark.Number }; Db.ArchivedProtocolRemarks.Add(aremark); } Db.ProtocolsRemarks.RemoveRange(protocol.ProtocolsRemarks); var products = diaryW.Products; foreach (var product in products) { var aproduct = new ArchivedProduct() { Id = Guid.NewGuid(), Name = product.Name, Number = product.Number, Quantity = product.Quantity }; var productTests = product.ProductTests; foreach (var ptest in productTests) { var aptest = new ArchivedProductTest() { Id = Guid.NewGuid(), TestName = ptest.Test.Name, TestUnitName = ptest.Test.UnitName, TestMethods = ptest.TestMethod.Method, TestAcredetationLevel = ptest.Test.AcredetationLevel.Level, TestTemperature = ptest.Test.Temperature, TestCategory = ptest.Test.TestCategory.Name, TestType = ptest.Test.TestType.Type, TestTypeShortName = ptest.Test.TestType.ShortName, MethodValue = ptest.MethodValue, Remark = ptest.Remark }; var protocolResults = ptest.ProtocolResults; foreach (var presult in protocolResults) { var apresult = new ArchivedProtocolResult() { Id = Guid.NewGuid(), Results = presult.Results, ResultNumber = presult.ResultNumber, ArchivedDiaryId = archivedDiary.Id }; aptest.ArchivedProtocolResults.Add(apresult); } Db.ProtocolResults.RemoveRange(ptest.ProtocolResults); aproduct.ArchivedProductTests.Add(aptest); } Db.ProductTests.RemoveRange(product.ProductTests); archivedDiary.ArchivedProducts.Add(aproduct); } Db.Products.RemoveRange(diaryW.Products); Db.ArchivedDiaries.Add(archivedDiary); Db.Protocols.RemoveRange(request.Protocols); Db.Requests.Remove(request); var diary = Db.Diaries.FirstOrDefault(x => x.Id == diaryW.Id); Db.Diaries.Remove(diary); Db.SaveChanges(); res.IsSuccess = true; res.ResponseObject = archivedDiary.Id; res.SuccessMsg = "Архивирането на дневник: " + diaryW.Number + " премина успешно."; } catch (DbEntityValidationException sqlEx) { foreach (var validationErrors in sqlEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } catch (Exception exc) { Elmah.ErrorSignal.FromCurrentContext().Raise(exc); res.Error = ErrorFactory.UnableToArchiveDiary; } return(res); }