public override HandleState Add(CatPartnerModel entity)
        {
            ICurrentUser _user = PermissionExtention.GetUserMenuPermission(currentUser, Menu.catPartnerdata);//Set default
            var          permissionRangeWrite = PermissionExtention.GetPermissionRange(_user.UserMenuPermission.Write);

            if (permissionRangeWrite == PermissionRange.None)
            {
                return(new HandleState(403, ""));
            }
            var partner = mapper.Map <CatPartner>(entity);

            partner.DatetimeCreated  = DateTime.Now;
            partner.DatetimeModified = DateTime.Now;
            partner.UserCreated      = partner.UserModified = currentUser.UserID;
            partner.Active           = true;
            partner.GroupId          = currentUser.GroupId;
            partner.DepartmentId     = currentUser.DepartmentId;
            partner.OfficeId         = currentUser.OfficeID;
            partner.CompanyId        = currentUser.CompanyID;
            var hs = DataContext.Add(partner);

            if (hs.Success)
            {
                if (entity.SaleMans.Count() > 0)
                {
                    var salemans = mapper.Map <List <CatSaleman> >(entity.SaleMans);
                    salemans.ForEach(x =>
                    {
                        x.Id          = Guid.NewGuid();
                        x.PartnerId   = partner.Id;
                        x.CreateDate  = DateTime.Now;
                        x.UserCreated = currentUser.UserID;
                        //x.CompanyId = currentUser.CompanyID;
                        //x.OfficeId = currentUser.OfficeID;
                        //x.GroupId = currentUser.GroupId;
                        //x.DepartmentId = currentUser.DepartmentId;
                    });
                    partner.SalePersonId = salemans.FirstOrDefault().SaleManId.ToString();
                    DataContext.Update(partner, x => x.Id == partner.Id);
                    salemanRepository.Add(salemans);
                }
                DataContext.SubmitChanges();
                salemanRepository.SubmitChanges();
                ClearCache();
                Get();
                SendMail.Send("Confirm Add Partner", webUrl.Value.Url.ToString() + "/en/#/home/catalogue/partner-data/detail/" + entity.Id, "*****@*****.**", null, null);
            }
            return(hs);
        }
Esempio n. 2
0
        public HandleState AddCharge(CatChargeAddOrUpdateModel model)
        {
            using (var trans = DataContext.DC.Database.BeginTransaction())
            {
                Guid chargeId = Guid.NewGuid();
                model.Charge.Id              = chargeId;
                model.Charge.Active          = true;
                model.Charge.UserCreated     = model.Charge.UserModified = currentUser.UserID;
                model.Charge.DatetimeCreated = DateTime.Now;

                // Update permission
                model.Charge.GroupId      = currentUser.GroupId;
                model.Charge.DepartmentId = currentUser.DepartmentId;
                model.Charge.OfficeId     = currentUser.OfficeID;
                model.Charge.CompanyId    = currentUser.CompanyID;

                try
                {
                    var hs = DataContext.Add(model.Charge, false);
                    if (hs.Success == false)
                    {
                        return(hs);
                    }
                    foreach (var x in model.ListChargeDefaultAccount)
                    {
                        x.ChargeId        = chargeId;
                        x.Active          = true;
                        x.UserCreated     = x.UserModified = currentUser.UserID;
                        x.DatetimeCreated = DateTime.Now;
                        chargeDefaultRepository.Add(x, false);
                    }
                    chargeDefaultRepository.SubmitChanges();
                    DataContext.SubmitChanges();
                    ClearCache();
                    Get();
                    trans.Commit();
                    return(hs);
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    return(new HandleState(ex.Message));
                }
                finally
                {
                    trans.Dispose();
                }
            }
        }
        public override HandleState Add(SysPermissionSampleModel entity)
        {
            var permision = mapper.Map <SysPermissionSample>(entity);

            permision.UserCreated     = permision.UserModified = currentUser.UserID;
            permision.DatetimeCreated = permision.DatetimeModified = DateTime.Now;
            var result = DataContext.Add(permision, false);

            if (result.Success)
            {
                foreach (var item in entity.SysPermissionSampleGenerals)
                {
                    var listGeneral = mapper.Map <List <SysPermissionSampleGeneral> >(item.SysPermissionGenerals);
                    foreach (var general in listGeneral)
                    {
                        general.PermissionId     = permision.Id;
                        general.DatetimeModified = DateTime.Now;
                        general.UserModified     = currentUser.UserID;
                        permissioSampleGeneralRepository.Add(general, false);
                    }
                }
                foreach (var item in entity.SysPermissionSampleSpecials)
                {
                    foreach (var per in item.SysPermissionSpecials)
                    {
                        foreach (var s in per.PermissionSpecialActions)
                        {
                            var peritem = new SysPermissionSampleSpecial
                            {
                                Id               = s.Id,
                                IsAllow          = s.IsAllow,
                                MenuId           = s.MenuId,
                                ModuleId         = s.ModuleId,
                                ActionName       = s.ActionName,
                                PermissionId     = permision.Id,
                                DatetimeModified = DateTime.Now,
                                UserModified     = currentUser.UserID
                            };
                            permissioSampleSpecialRepository.Add(peritem, false);
                        }
                    }
                }
                permissioSampleSpecialRepository.SubmitChanges();
                DataContext.SubmitChanges();
                permissioSampleGeneralRepository.SubmitChanges();
            }
            return(result);
        }
        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(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());
        }
Esempio 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);
        }