public HandleState Update(List <CsMawbcontainerModel> list, Guid?masterId, Guid?housebillId) { try { if (masterId != null) { List <CsMawbcontainer> oldList = null; oldList = DataContext.Where(x => x.Mblid == masterId).ToList(); foreach (var item in oldList) { if (list.FirstOrDefault(x => x.Id == item.Id) == null) { DataContext.Delete(x => x.Id == item.Id, false); } } if (housebillId != null) { List <CsMawbcontainer> oldHouseList = null; oldHouseList = DataContext.Where(x => x.Hblid == housebillId && x.Mblid == masterId).ToList(); foreach (var item in oldHouseList) { if (list.FirstOrDefault(x => x.Id == item.Id) == null) { DataContext.Delete(x => x.Id == item.Id, false); } } } } Hashtable ht = new Hashtable(); int sumCont = 0; decimal sumGW = 0; decimal sumNW = 0; decimal sumCW = 0; decimal sumCBM = 0; int sumPackages = 0; foreach (var item in list) { sumCont = sumCont + (int)item.Quantity; sumGW = sumGW + (item.Gw != null?(long)item.Gw: 0); sumNW = sumNW + (item.Nw != null?(long)item.Nw: 0); sumCW = sumCW + (item.ChargeAbleWeight != null?(long)item.ChargeAbleWeight: 0); sumCBM = sumCBM + (item.Cbm != null? (long)item.Cbm: 0); sumPackages = sumPackages + (item.PackageQuantity != null? (int)item.PackageQuantity: 0); if (ht.ContainsKey(item.ContainerTypeName)) { var sumContDes = Convert.ToInt32(ht[item.ContainerTypeName]) + item.Quantity; ht[item.ContainerTypeName] = sumContDes; } else { ht.Add(item.ContainerTypeName, item.Quantity); } if (item.Id == Guid.Empty) { item.Id = Guid.NewGuid(); item.UserModified = currentUser.UserID; item.Mblid = (Guid)masterId; item.DatetimeModified = DateTime.Now; var hs = Add(item, false); } else { if (DataContext.Count(x => x.Id == item.Id) == 1) { item.UserModified = currentUser.UserID; item.DatetimeModified = DateTime.Now; var hs = Update(item, x => x.Id == item.Id, false); } } } var opstrans = opsTransRepository.First(x => x.Id == masterId); if (ht.Count > 0) { var containerDes = string.Empty; ICollection keys = ht.Keys; foreach (var key in keys) { containerDes = containerDes + ht[key] + "x" + key + "; "; } containerDes = containerDes.Substring(0, containerDes.Length - 2); opstrans.SumCbm = sumCBM != 0? (decimal?)sumCBM: null; opstrans.SumChargeWeight = sumCW != 0 ? (decimal?)sumCW : null; opstrans.SumGrossWeight = sumGW != 0 ? (decimal?)sumGW : null; opstrans.SumNetWeight = sumNW != 0 ? (decimal?)sumNW : null; opstrans.SumPackages = sumPackages != 0 ? (int?)sumPackages : null; opstrans.SumContainers = sumCont != 0 ? (int?)sumCont : null; opstrans.ContainerDescription = containerDes; } else { opstrans.SumCbm = opstrans.SumChargeWeight = opstrans.SumGrossWeight = opstrans.SumNetWeight = opstrans.SumPackages = opstrans.SumContainers = null; opstrans.ContainerDescription = null; } opstrans.DatetimeModified = DateTime.Now; opstrans.UserModified = currentUser.UserID; opsTransRepository.Update(opstrans, x => x.Id == masterId, false); DataContext.SubmitChanges(); opsTransRepository.SubmitChanges(); } catch (Exception ex) { return(new HandleState(ex.Message)); } return(new HandleState()); }
public HandleState Update(SysPermissionSampleModel entity) { var permission = mapper.Map <SysPermissionSample>(entity); permission.UserModified = currentUser.UserID; permission.DatetimeModified = DateTime.Now; var result = DataContext.Update(permission, x => x.Id == entity.Id, false); if (result.Success) { foreach (var item in entity.SysPermissionSampleGenerals) { var list = mapper.Map <List <SysPermissionSampleGeneral> >(item.SysPermissionGenerals); foreach (var general in list) { general.UserModified = currentUser.UserID; general.DatetimeModified = DateTime.Now; if (general.Id == 0) { permissioSampleGeneralRepository.Add(general, false); } else { permissioSampleGeneralRepository.Update(general, x => x.Id == general.Id, false); } } } foreach (var item in entity.SysPermissionSampleSpecials) { foreach (var per in item.SysPermissionSpecials) { foreach (var s in per.PermissionSpecialActions) { if (s.Id == 0) { var peritem = mapper.Map <SysPermissionSampleSpecial>(s); peritem.Id = s.Id; peritem.IsAllow = s.IsAllow; peritem.MenuId = s.MenuId; peritem.ModuleId = s.ModuleId; peritem.ActionName = s.ActionName; peritem.PermissionId = entity.Id; peritem.UserModified = currentUser.UserID; peritem.DatetimeModified = DateTime.Now; permissioSampleSpecialRepository.Add(peritem, false); } else { var peritem = permissioSampleSpecialRepository.First(x => x.Id == s.Id); peritem.IsAllow = s.IsAllow; peritem.UserModified = currentUser.UserID; peritem.DatetimeModified = DateTime.Now; var t = permissioSampleSpecialRepository.Update(peritem, x => x.Id == s.Id, true); } } } } DataContext.SubmitChanges(); permissioSampleGeneralRepository.SubmitChanges(); permissioSampleSpecialRepository.SubmitChanges(); } return(result); }
public HandleState Update(OpsStageAssignedEditModel model) { var assigned = mapper.Map <OpsStageAssigned>(model); assigned.UserModified = currentUser.UserID; assigned.DatetimeModified = DateTime.Now; var stageAssigneds = DataContext.Get(x => x.JobId == model.JobId); var job = opsTransRepository.First(x => x.Id == model.JobId); var jobCsTransaction = csTransactionReporsitory.First(x => x.Id == model.JobId); if (job == null) { if (jobCsTransaction.CurrentStatus != OperationConstants.Deleted && jobCsTransaction.CurrentStatus != OperationConstants.Finish) { if (assigned.Status?.Trim() == DataTypeEx.GetStageStatus(StageEnum.Overdue)) { jobCsTransaction.CurrentStatus = OperationConstants.Overdue; } if (assigned.Status.Contains(DataTypeEx.GetStageStatus(StageEnum.Done))) { var others = stageAssigneds.Where(x => x.Id != model.Id); if (others.All(x => x.Status.Contains(OperationConstants.Done))) { jobCsTransaction.CurrentStatus = OperationConstants.Finish; } } if (jobCsTransaction.CurrentStatus?.Trim() == OperationConstants.InSchedule && assigned.Status.Trim() == OperationConstants.Processing) { jobCsTransaction.CurrentStatus = OperationConstants.Processing; } } } else { if (job.CurrentStatus != OperationConstants.Deleted && job.CurrentStatus != OperationConstants.Finish) { if (assigned.Status?.Trim() == DataTypeEx.GetStageStatus(StageEnum.Overdue)) { job.CurrentStatus = OperationConstants.Overdue; } if (assigned.Status.Contains(DataTypeEx.GetStageStatus(StageEnum.Done))) { var others = stageAssigneds.Where(x => x.Id != model.Id); if (others.All(x => x.Status.Contains(OperationConstants.Done))) { job.CurrentStatus = OperationConstants.Finish; } } if (job.CurrentStatus?.Trim() == OperationConstants.InSchedule && assigned.Status.Trim() == OperationConstants.Processing) { job.CurrentStatus = OperationConstants.Processing; } } } var result = new HandleState(); try { result = DataContext.Update(assigned, x => x.Id == assigned.Id, false); SubmitChanges(); if (result.Success) { if (job == null) { csTransactionReporsitory.Update(jobCsTransaction, x => x.Id == jobCsTransaction.Id); csTransactionReporsitory.SubmitChanges(); } else { opsTransRepository.Update(job, x => x.Id == job.Id); opsTransRepository.SubmitChanges(); } } } catch (Exception ex) { result = new HandleState(ex.Message); } return(result); }