public HandleState AddOrUpdateManifest(CsManifestEditModel model)
        {
            try
            {
                var manifest = mapper.Map <CsManifest>(model);
                manifest.CreatedDate = DateTime.Now;
                var hs = new HandleState();
                manifest.RefNo = GetManifestNo(model.JobId);
                if (DataContext.Any(x => x.JobId == model.JobId))
                {
                    hs = DataContext.Update(manifest, x => x.JobId == model.JobId);
                }
                else
                {
                    hs = DataContext.Add(manifest);
                }
                if (hs.Success)
                {
                    foreach (var item in model.CsTransactionDetails)
                    {
                        if (item.IsRemoved)
                        {
                            item.ManifestRefNo = null;
                        }
                        else
                        {
                            item.ManifestRefNo = manifest.RefNo;
                        }
                        item.DatetimeModified = DateTime.Now;
                        item.UserModified     = manifest.UserCreated;
                        var tranDetail = mapper.Map <CsTransactionDetail>(item);
                        var s          = transactionDetailRepository.Update(tranDetail, x => x.Id == tranDetail.Id);
                    }
                    transactionDetailRepository.SubmitChanges();
                    DataContext.SubmitChanges();
                }

                return(hs);
            }
            catch (Exception ex)
            {
                var hs = new HandleState(ex.Message);
                return(hs);
            }
        }
        public HandleState Update(CatPartnerModel model)
        {
            var          listSalemans    = salemanRepository.Get(x => x.PartnerId == model.Id).ToList();
            ICurrentUser _user           = PermissionExtention.GetUserMenuPermission(currentUser, Menu.catPartnerdata);//Set default
            var          permissionRange = PermissionExtention.GetPermissionRange(_user.UserMenuPermission.Write);

            int code = GetPermissionToUpdate(new ModelUpdate {
                UserCreator = model.UserCreated, Salemans = listSalemans, PartnerGroup = model.PartnerGroup
            }, permissionRange, null);

            if (code == 403)
            {
                return(new HandleState(403, ""));
            }
            var entity = mapper.Map <CatPartner>(model);

            entity.DatetimeModified = DateTime.Now;
            entity.UserModified     = currentUser.UserID;
            entity.GroupId          = currentUser.GroupId;
            entity.CompanyId        = currentUser.CompanyID;
            entity.OfficeId         = currentUser.OfficeID;
            entity.DepartmentId     = currentUser.DepartmentId;

            if (entity.Active == false)
            {
                entity.InactiveOn = DateTime.Now;
            }
            if (model.SaleMans.Count > 0)
            {
                entity.SalePersonId = model.SaleMans.FirstOrDefault().SaleManId.ToString();
            }
            var hs = DataContext.Update(entity, x => x.Id == model.Id);

            if (hs.Success)
            {
                var hsoldman = salemanRepository.Delete(x => x.PartnerId == model.Id && !model.SaleMans.Any(sale => sale.Id == x.Id));
                var salemans = mapper.Map <List <CatSaleman> >(model.SaleMans);

                foreach (var item in model.SaleMans)
                {
                    if (item.Id == Guid.Empty)
                    {
                        item.Id          = Guid.NewGuid();
                        item.PartnerId   = entity.Id;
                        item.CreateDate  = DateTime.Now;
                        item.UserCreated = currentUser.UserID;
                        //item.CompanyId = currentUser.CompanyID;
                        //item.OfficeId = currentUser.OfficeID;
                        //item.GroupId = currentUser.GroupId;
                        //item.DepartmentId = currentUser.DepartmentId;
                        salemanRepository.Add(item);
                    }
                    else
                    {
                        item.ModifiedDate = DateTime.Now;
                        item.UserModified = currentUser.UserID;
                        salemanRepository.Update(item, x => x.Id == item.Id);
                    }
                }
                salemanRepository.SubmitChanges();
                ClearCache();
                Get();
            }
            return(hs);
        }
        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(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());
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Update tariff & list tariff model
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public HandleState UpdateTariff(TariffModel model)
        {
            try
            {
                var today = DateTime.Now;
                //Update SetTariff
                var tariff = mapper.Map <SetTariff>(model.setTariff);
                //var tariffCurrent = DataContext.Get(x => x.Id == tariff.Id).FirstOrDefault();
                //tariff.UserCreated = tariffCurrent.UserCreated;
                //tariff.DatetimeCreated = tariffCurrent.DatetimeCreated;
                tariff.DatetimeModified = today;

                var hs = DataContext.Update(tariff, x => x.Id == tariff.Id);
                if (hs.Success)
                {
                    var tariffDetails = mapper.Map <List <SetTariffDetail> >(model.setTariffDetails);

                    //Remove các tariff mà user đã gỡ bỏ
                    var listIdTariffDetail           = tariffDetails.Select(s => s.Id);
                    var listIdTariffDetailNeedRemove = setTariffDetailRepo.Get(x => x.TariffId == tariff.Id &&
                                                                               !listIdTariffDetail.Contains(x.Id)).Select(x => x.Id);
                    if (listIdTariffDetailNeedRemove.Count() > 0)
                    {
                        var hsTariffDetailDel = setTariffDetailRepo.Delete(x => listIdTariffDetailNeedRemove.Contains(x.Id));
                    }

                    //Update các tariff detail cũ
                    var tariffDetailOld = tariffDetails.Where(x => x.Id != Guid.Empty);
                    //&& setTariffDetailRepo.Get(g => g.TariffId == tariff.Id).Select(s => s.Id).Contains(x.Id));
                    if (tariffDetailOld.Count() > 0)
                    {
                        foreach (var item in tariffDetailOld)
                        {
                            //item.UserCreated = setTariffDetailRepo.Get(x => x.Id == item.Id).FirstOrDefault().UserCreated;
                            item.UserModified = model.setTariff.UserModified;
                            //item.DatetimeCreated = setTariffDetailRepo.Get(x => x.Id == item.Id).FirstOrDefault().DatetimeCreated;
                            item.DatetimeModified = DateTime.Now;
                            var hsTariffDetailUpdate = setTariffDetailRepo.Update(item, x => x.Id == item.Id);
                        }
                    }

                    //Add các tariff detail mới
                    var tariffDetailNew = tariffDetails.Where(x => x.Id == Guid.Empty).ToList();
                    if (tariffDetailNew.Count > 0)
                    {
                        tariffDetailNew.ForEach(r =>
                        {
                            r.Id              = Guid.NewGuid();
                            r.TariffId        = tariff.Id;
                            r.UserCreated     = r.UserModified = model.setTariff.UserModified;
                            r.DatetimeCreated = r.DatetimeModified = DateTime.Now;
                        });
                        var hsTariffDetailAdd = setTariffDetailRepo.Add(tariffDetailNew);
                    }
                }

                return(hs);
            }
            catch (Exception ex)
            {
                return(new HandleState(ex.Message));
            }
        }
Ejemplo n.º 6
0
        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);
        }