public ActionResult UpdateRequestTake([DataSourceRequest] DataSourceRequest request, TmcInView dictionary) { if (dictionary.Id == Guid.Empty) { dictionary.Id = dictionary.TmcInId; } TmcIn d = db.TmcIns.First(o => o.Id == dictionary.Id); bool isContractChange = d.ContractNumber != dictionary.ContractNumber; d.StateType = dictionary.StateType; d.ContractDate = dictionary.ContractDate; d.ContractNumber = dictionary.ContractNumber; d.IsFullDelivery = dictionary.IsFullDelivery; d.LastDeliveryDate = dictionary.LastDeliveryDate; d.OwnerEmployeeId = dictionary.OwnerEmployeeId; d.Provider = dictionary.Provider; d.ProviderBin = dictionary.ProviderBin; d.ExecutorEmployeeId = dictionary.ExecutorEmployeeId; d.AgreementEmployeeId = dictionary.AgreementEmployeeId; d.AccountantEmployeeId = dictionary.AccountantEmployeeId; db.SaveChanges(); dictionary = db.TmcInViews.First(o => o.Id == d.Id); if (isContractChange) { TmcRepository tmcRepo = new TmcRepository(); tmcRepo.RemoveTmcByPoaId(dictionary.Id); var dicRepo = new DictionaryRepository(false); var contractProducts = tmcRepo.GetI1cLimsContractProducts(lc => lc.ContractNumber == d.ContractNumber); foreach (var prod in contractProducts.ToList()) { var measureId = dicRepo.GetDictionaryIdByTypeAndDisplayName(Dictionary.MeasureType.DicCode, prod.Unit); var t = new Tmc() { Id = Guid.NewGuid(), CreatedDate = DateTime.Now, CreatedEmployeeId = UserHelper.GetCurrentEmployee().Id, TmcInId = d.Id, StateType = 0, Number = prod.ProductId, Code = prod.ProductId, Name = prod.Name, Count = prod.QuantityVolume.Value, CountActual = prod.QuantityVolume.Value, CountFact = prod.QuantityVolume.Value, CountConvert = prod.QuantityVolume.Value, MeasureTypeDicId = measureId, MeasureTypeConvertDicId = measureId }; tmcRepo.Insert(t); } tmcRepo.Save(); } return(Json(new[] { dictionary }.ToDataSourceResult(request, ModelState))); }
public ActionResult UpdateApplication([DataSourceRequest] DataSourceRequest request, TmcInView model) { if (model.Id == Guid.Empty) { model.Id = model.TmcInId; } ApplicationPoaRepository repo = new ApplicationPoaRepository(false); TmcIn d = repo.GetAsQuarable(o => o.Id == model.Id).FirstOrDefault(); bool isContractChange = d.ContractNumber != model.ContractNumber; d.StateType = model.StateType; d.ContractDate = model.ContractDate; d.ContractNumber = model.ContractNumber; d.IsFullDelivery = model.IsFullDelivery; d.LastDeliveryDate = model.LastDeliveryDate; d.OwnerEmployeeId = model.OwnerEmployeeId; d.Provider = model.Provider; d.ProviderBin = model.ProviderBin; d.ExecutorEmployeeId = model.ExecutorEmployeeId; d.AgreementEmployeeId = model.AgreementEmployeeId; d.AccountantEmployeeId = model.AccountantEmployeeId; repo.Save(); model = repo.GetTmcInViews(o => o.Id == d.Id).FirstOrDefault(); if (isContractChange) { TmcRepository tmcRepo = new TmcRepository(); tmcRepo.RemoveTmcByPoaId(model.Id); var dicRepo = new DictionaryRepository(false); var contractProducts = tmcRepo.GetI1cLimsContractProducts(lc => lc.ContractNumber == d.ContractNumber); foreach (var prod in contractProducts.ToList()) { var measureId = dicRepo.GetDictionaryIdByTypeAndDisplayName(Dictionary.MeasureType.DicCode, prod.Unit); var tmc = new Tmc() { Id = Guid.NewGuid(), CreatedDate = DateTime.Now, CreatedEmployeeId = UserHelper.GetCurrentEmployee().Id, TmcInId = d.Id, StateType = 0, Number = prod.ProductId, Code = prod.ProductId, Name = prod.Name, Count = prod.QuantityVolume.Value, CountActual = prod.QuantityVolume.Value, CountFact = prod.QuantityVolume.Value, CountConvert = prod.QuantityVolume.Value, MeasureTypeDicId = measureId, MeasureTypeConvertDicId = measureId }; var tmcExist = tmcRepo.GetAsQuarable(t => t.Number == tmc.Number && t.CountFact < t.Count).FirstOrDefault(); if (tmcExist == null) { tmcRepo.Insert(tmc); var limsTmc = new LimsTmcTemp() { TmcId = tmc.Id, TmcInId = tmc.TmcInId, CreatedDate = DateTime.Now, CountRequest = tmc.Count, IsSelected = false }; repo.AddLimsTmcTemp(limsTmc); } else { var limsTmc = new LimsTmcTemp() { TmcId = tmc.Id, TmcInId = tmc.TmcInId, CreatedDate = DateTime.Now, CountRequest = prod.QuantityVolume.Value - tmcExist.CountFact, IsSelected = false }; if (prod.QuantityVolume.Value - tmcExist.CountFact > 0) { repo.AddLimsTmcTemp(limsTmc); } } } tmcRepo.Save(); repo.Save(); } return(Json(new[] { model }.ToDataSourceResult(request, ModelState))); }
public ActionResult CreateRequestTake([DataSourceRequest] DataSourceRequest request, TmcInViewModel dictionary) { if (ModelState.IsValid) { TmcIn tmc = new TmcIn() { Id = Guid.NewGuid(), StateType = dictionary.StateType, ContractDate = dictionary.ContractDate, ContractNumber = dictionary.ContractNumber, CreatedDate = DateTime.Now, CreatedEmployeeId = UserHelper.GetCurrentEmployee().Id, IsFullDelivery = dictionary.IsFullDelivery, LastDeliveryDate = dictionary.LastDeliveryDate, OwnerEmployeeId = dictionary.OwnerEmployeeId, Provider = dictionary.Provider, ProviderBin = dictionary.ProviderBin, ExecutorEmployeeId = dictionary.ExecutorEmployeeId, AgreementEmployeeId = dictionary.AgreementEmployeeId, AccountantEmployeeId = dictionary.AccountantEmployeeId }; db.TmcIns.Add(tmc); db.SaveChanges(); var newDictionary = db.TmcInViews.First(o => o.Id == tmc.Id); dictionary.TmcInId = tmc.Id; dictionary.OwnerEmployeeValue = newDictionary.OwnerEmployeeValue; dictionary.StateTypeValue = newDictionary.StateTypeValue; dictionary.PowerOfAttorney = newDictionary.PowerOfAttorney; dictionary.IsFullDeliveryValue = newDictionary.IsFullDeliveryValue; dictionary.ExecutorEmployeeValue = newDictionary.ExecutorEmployeeValue; dictionary.AgreementEmployeeValue = newDictionary.AgreementEmployeeValue; dictionary.AccountantEmployeeValue = newDictionary.AccountantEmployeeValue; dictionary.Id = newDictionary.Id; TmcRepository tmcRepo = new TmcRepository(); var dicRepo = new DictionaryRepository(false); var contractProducts = tmcRepo.GetI1cLimsContractProducts(lc => lc.ContractNumber == tmc.ContractNumber); foreach (var prod in contractProducts.ToList()) { var measureId = dicRepo.GetDictionaryIdByTypeAndDisplayName(Dictionary.MeasureType.DicCode, prod.Unit); var t = new Tmc() { Id = Guid.NewGuid(), CreatedDate = DateTime.Now, CreatedEmployeeId = UserHelper.GetCurrentEmployee().Id, TmcInId = tmc.Id, StateType = 0, Number = prod.ProductId, Code = prod.ProductId, Name = prod.Name, Count = prod.QuantityVolume.Value, CountActual = prod.QuantityVolume.Value, CountFact = prod.QuantityVolume.Value, CountConvert = prod.QuantityVolume.Value, MeasureTypeDicId = measureId, MeasureTypeConvertDicId = measureId }; tmcRepo.Insert(t); } tmcRepo.Save(); } return(Json(new[] { dictionary }.ToDataSourceResult(request, ModelState))); }
public ActionResult CreateApplication([DataSourceRequest] DataSourceRequest request, TmcInViewModel model) { if (ModelState.IsValid) { ApplicationPoaRepository repo = new ApplicationPoaRepository(false); TmcIn tmcIn = new TmcIn() { Id = Guid.NewGuid(), StateType = model.StateType, ContractDate = model.ContractDate, ContractNumber = model.ContractNumber, CreatedDate = DateTime.Now, CreatedEmployeeId = UserHelper.GetCurrentEmployee().Id, IsFullDelivery = model.IsFullDelivery, LastDeliveryDate = model.LastDeliveryDate, OwnerEmployeeId = model.OwnerEmployeeId, Provider = model.Provider, ProviderBin = model.ProviderBin, ExecutorEmployeeId = model.ExecutorEmployeeId, AgreementEmployeeId = model.AgreementEmployeeId, AccountantEmployeeId = model.AccountantEmployeeId }; repo.Insert(tmcIn); repo.Save(); var newDictionary = repo.GetTmcInViews(o => o.Id == tmcIn.Id).First(); model.TmcInId = tmcIn.Id; model.OwnerEmployeeValue = newDictionary.OwnerEmployeeValue; model.StateTypeValue = newDictionary.StateTypeValue; model.PowerOfAttorney = newDictionary.PowerOfAttorney; model.IsFullDeliveryValue = newDictionary.IsFullDeliveryValue; model.ExecutorEmployeeValue = newDictionary.ExecutorEmployeeValue; model.AgreementEmployeeValue = newDictionary.AgreementEmployeeValue; model.AccountantEmployeeValue = newDictionary.AccountantEmployeeValue; model.Id = newDictionary.Id; TmcRepository tmcRepo = new TmcRepository(); var dicRepo = new DictionaryRepository(false); var contractProducts = tmcRepo.GetI1cLimsContractProducts(lc => lc.ContractNumber == tmcIn.ContractNumber); foreach (var prod in contractProducts.ToList()) { var measureId = dicRepo.GetDictionaryIdByTypeAndDisplayName(Dictionary.MeasureType.DicCode, prod.Unit); if (measureId == null || measureId == Guid.Empty) { measureId = dicRepo.GetDictionaryIdByTypeAndName(Dictionary.MeasureType.DicCode, prod.Unit); } var tmc = new Tmc() { Id = Guid.NewGuid(), CreatedDate = DateTime.Now, CreatedEmployeeId = UserHelper.GetCurrentEmployee().Id, TmcInId = tmcIn.Id, StateType = 0, Number = prod.ProductId, Code = prod.ProductId, Name = prod.Name, Count = prod.QuantityVolume.Value, CountActual = 0, //prod.QuantityVolume.Value, CountFact = 0, //prod.QuantityVolume.Value, CountConvert = 0, // prod.QuantityVolume.Value, MeasureTypeDicId = measureId, MeasureTypeConvertDicId = measureId }; var tmcExist = tmcRepo.GetAsQuarable(t => t.Number == tmc.Number && t.StateType != Tmc.TmcStatuses.Writeoff).FirstOrDefault(); if (tmcExist == null) { tmcRepo.Insert(tmc); var limsTmc = new LimsTmcTemp() { TmcId = tmc.Id, TmcInId = tmc.TmcInId, CreatedDate = DateTime.Now, CountRequest = tmc.Count, IsSelected = false }; repo.AddLimsTmcTemp(limsTmc); } else if (tmcExist.CountFact < tmcExist.Count) { var limsTmc = new LimsTmcTemp() { TmcId = tmcExist.Id, TmcInId = tmcIn.Id, CreatedDate = DateTime.Now, CountRequest = prod.QuantityVolume.Value - tmcExist.CountFact, IsSelected = false }; if (prod.QuantityVolume.Value - tmcExist.CountFact > 0) { repo.AddLimsTmcTemp(limsTmc); } } } tmcRepo.Save(); repo.Save(); } return(Json(new[] { model }.ToDataSourceResult(request, ModelState))); }