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);
        }
Exemplo 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);
        }
        /// <summary>
        /// Add tariff & list tariff detail
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public HandleState AddTariff(TariffModel model)
        {
            try
            {
                var userCurrent = currentUser.UserID;
                var today       = DateTime.Now;

                model.setTariff.GroupId      = currentUser.GroupId;
                model.setTariff.DepartmentId = currentUser.DepartmentId;
                model.setTariff.OfficeId     = currentUser.OfficeID;
                model.setTariff.CompanyId    = currentUser.CompanyID;
                //Insert SetTariff
                var tariff = mapper.Map <SetTariff>(model.setTariff);
                tariff.Id              = model.setTariff.Id = Guid.NewGuid();
                tariff.UserCreated     = tariff.UserModified = userCurrent;
                tariff.DatetimeCreated = tariff.DatetimeModified = today;
                var hs = DataContext.Add(tariff);
                if (hs.Success)
                {
                    //Insert list SetTariffDetail
                    var tariffDetails = mapper.Map <List <SetTariffDetail> >(model.setTariffDetails);
                    tariffDetails.ForEach(r =>
                    {
                        r.Id              = Guid.NewGuid();
                        r.TariffId        = tariff.Id;
                        r.UserCreated     = r.UserModified = userCurrent;
                        r.DatetimeCreated = r.DatetimeModified = today;
                    });
                    var hsTariffDetail = setTariffDetailRepo.Add(tariffDetails);
                }
                return(hs);
            }
            catch (Exception ex)
            {
                return(new HandleState(ex.Message));
            }
        }