public SchoolView Save(SchoolView view)
        {
            var dtNow = DateTime.Now;
            var model = view.Id > 0
                ? _repository.GetById <School>(view.Id)
                : new School {
                RecordStatus = (long)SysMngConfig.RecordStatuses.Active
            };

            view.SetTo(model);

            var companySchoolUser = Settings.GetSetting <string>("CompanySchoolUser");

            if (model.Users.All(k => k.UserName != companySchoolUser))
            {
                var user = _repository.Query <User>().FirstOrDefault(d => d.UserName == companySchoolUser);
                if (user != null)
                {
                    model.AddUser(user);
                }
            }

            if (view.Id > 0)
            {
                _repository.Update(model);
            }
            else
            {
                _repository.Create(model);
            }
            return(model.ToView <SchoolView>());
        }
        public IActionResult Create(Config model)
        {
            string note = AppGlobal.InitString;

            model.Initialization(InitType.Insert, RequestUserID);
            int result = _configResposistory.Create(model);

            if (result > 0)
            {
                note = AppGlobal.Success + " - " + AppGlobal.CreateSuccess;
            }
            else
            {
                note = AppGlobal.Success + " - " + AppGlobal.CreateFail;
            }
            return(Json(note));
        }
示例#3
0
        public async Task <Result> Create(Config model)
        {
            try
            {
                return(ModelState.IsValid ? await _config.Create(model) : Result.Failed);
            }
            catch (Exception e)
            {
                await _logger.AddException(e);

                return(Result.Failed);
            }
        }
        public ActionResult <string> Create(Config model)
        {
            Result routeResult;

            model.Initialization(InitType.Insert, RequestUserID);
            int result = _configResposistory.Create(model);

            if (result > 0)
            {
                routeResult = new Result()
                              .setResultType(ResultType.Success)
                              .setMessage(AppGlobal.CreateSuccess);
            }
            else
            {
                routeResult = new Result()
                              .setResultType(ResultType.Error)
                              .setErrorType(ErrorType.InsertError)
                              .setMessage(AppGlobal.CreateFail);
            }

            return(ObjectToJson(routeResult));
        }
示例#5
0
        public void SaveUser(UserViewModel user)
        {
            var isNew = user.UserId == 0;

            var entity = isNew ? new User() : _repository.GetById <User>(user.UserId);

            if (isNew && _repository.Query <User>().Any(u => u.UserName == user.UserName))
            {
                throw new Exception("This email address already exists in our system.");
            }

            if (entity.AlgorithmType == null)
            {
                entity.AlgorithmType = new AlgorithmType {
                    Id = 105001
                }
            }
            ;
            if (entity.PasswordFormatType == null)
            {
                entity.PasswordFormatType = new PasswordFormatType {
                    Id = 103001
                }
            }
            ;
            entity.UserType = new UserType {
                Id = user.UserTypeId
            };

            if (entity.Password == null)
            {
                entity.Password = "";
            }
            if (entity.PasswordSalt == null)
            {
                entity.PasswordSalt = "";
            }

            entity.FirstName = user.FirstName;
            entity.LastName  = user.LastName;
            entity.UserName  = user.UserName;


            if (entity.UserLoginInfo == null)
            {
                entity.SetUserLoginInfo(new UserLoginInfo());
            }

            var loginInfo = entity.UserLoginInfo;

            loginInfo.IsApprove = true;
            loginInfo.IsLocked  = false;

            if (isNew)
            {
                _repository.Create(entity);
                user.UserId = entity.Id;
            }
            else
            {
                _repository.Update(entity);
            }

            var email = entity.Communications.FirstOrDefault(
                c => c.IsPrimary && c.CommunicationType.Id == (long)CommunicationTypes.Email) ??
                        new Communication
            {
                CommunicationType = new CommunicationType {
                    Id = (long)CommunicationTypes.Email
                },
                Description  = "Email",
                Phone        = "",
                IsPrimary    = true,
                RecordStatus = new RecordStatus {
                    Id = (long)RecordStatuses.Active
                }
            };

            email.Email = user.UserName;
            if (email.Id == 0)
            {
                email.Users.Add(entity);
                _repository.Create(email);
            }
            else
            {
                _repository.Update(email);
            }

            var phone = entity.Communications.FirstOrDefault(
                c => c.IsPrimary && c.CommunicationType.Id == (long)CommunicationTypes.WorkPhone) ??
                        new Communication
            {
                CommunicationType = new CommunicationType {
                    Id = (long)CommunicationTypes.WorkPhone
                },
                Description  = "WorkPhone",
                Email        = "",
                IsPrimary    = true,
                RecordStatus = new RecordStatus {
                    Id = (long)RecordStatuses.Active
                }
            };

            phone.Phone = user.Phone;
            if (phone.Id == 0)
            {
                phone.Users.Add(entity);
                _repository.Create(phone);
            }
            else
            {
                _repository.Update(phone);
            }
        }
示例#6
0
        public IActionResult CreateNganHang(Config model)
        {
            Initialization(model);
            model.GroupName = AppGlobal.CRM;
            model.Code      = AppGlobal.NganHang;
            model.ParentID  = 0;
            string note = AppGlobal.InitString;

            model.Initialization(InitType.Insert, RequestUserID);
            int    result = 0;
            Config config = _configResposistory.GetByGroupNameAndCodeAndTitle(model.GroupName, model.Code, model.Title);

            if (config == null)
            {
                result = _configResposistory.Create(model);
            }
            if (result > 0)
            {
                note = AppGlobal.Success + " - " + AppGlobal.CreateSuccess;
            }
            else
            {
                note = AppGlobal.Error + " - " + AppGlobal.CreateFail;
            }
            return(Json(note));
        }
        public ActionResult UploadInvoice(BaseViewModel viewModel)
        {
            int    result     = 0;
            string action     = "Upload";
            string controller = "Membership";

            try
            {
                if (Request.Form.Files.Count > 0)
                {
                    var file = Request.Form.Files[0];
                    if (file == null || file.Length == 0)
                    {
                    }
                    if (file != null)
                    {
                        string fileExtension = Path.GetExtension(file.FileName);
                        string fileName      = Path.GetFileNameWithoutExtension(file.FileName);
                        fileName = "Invoice";
                        fileName = fileName + "-" + AppGlobal.DateTimeCode + fileExtension;
                        var physicalPath = Path.Combine(_hostingEnvironment.WebRootPath, AppGlobal.FTPUploadExcel, fileName);
                        using (var stream = new FileStream(physicalPath, FileMode.Create))
                        {
                            file.CopyTo(stream);
                            FileInfo fileLocation = new FileInfo(physicalPath);
                            if (fileLocation.Length > 0)
                            {
                                if ((fileExtension == ".xlsx") || (fileExtension == ".xls"))
                                {
                                    using (ExcelPackage package = new ExcelPackage(stream))
                                    {
                                        if (package.Workbook.Worksheets.Count > 0)
                                        {
                                            ExcelWorksheet workSheet = package.Workbook.Worksheets[1];
                                            if (workSheet != null)
                                            {
                                                int totalRows = workSheet.Dimension.Rows;
                                                for (int i = 2; i <= totalRows; i++)
                                                {
                                                    Membership model = new Membership();
                                                    if (workSheet.Cells[i, 7].Value != null)
                                                    {
                                                        model.TaxCode = workSheet.Cells[i, 7].Value.ToString().Trim();
                                                        model.TaxCode = model.TaxCode.Replace(@" ", @"");
                                                        model         = _membershipRepository.GetByTaxCode(model.TaxCode);
                                                        if (model != null)
                                                        {
                                                            MembershipProperty membershipProperty = new MembershipProperty();
                                                            membershipProperty.MembershipID = model.ID;
                                                            if (workSheet.Cells[i, 1].Value != null)
                                                            {
                                                                membershipProperty.PaymentCode = workSheet.Cells[i, 1].Value.ToString().Trim();
                                                            }
                                                            if (workSheet.Cells[i, 2].Value != null)
                                                            {
                                                                membershipProperty.ProductCode = workSheet.Cells[i, 2].Value.ToString().Trim();
                                                            }
                                                            decimal valueContract = 0;
                                                            if (workSheet.Cells[i, 3].Value != null)
                                                            {
                                                                try
                                                                {
                                                                    valueContract = decimal.Parse(workSheet.Cells[i, 3].Value.ToString().Trim());
                                                                }
                                                                catch
                                                                {
                                                                }
                                                            }
                                                            membershipProperty = _membershipPropertyRepository.GetByMembershipIDAndPaymentCodeAndProductCode(membershipProperty.MembershipID.Value, membershipProperty.PaymentCode, membershipProperty.ProductCode);
                                                            if (membershipProperty == null)
                                                            {
                                                                membershipProperty = new MembershipProperty();
                                                                membershipProperty.MembershipID = model.ID;
                                                                if (workSheet.Cells[i, 1].Value != null)
                                                                {
                                                                    membershipProperty.PaymentCode = workSheet.Cells[i, 1].Value.ToString().Trim();
                                                                }
                                                                if (workSheet.Cells[i, 2].Value != null)
                                                                {
                                                                    membershipProperty.ProductCode = workSheet.Cells[i, 2].Value.ToString().Trim();
                                                                }
                                                                Config product = new Config();
                                                                if (workSheet.Cells[i, 4].Value != null)
                                                                {
                                                                    product.Title = workSheet.Cells[i, 4].Value.ToString().Trim();
                                                                    product       = _configResposistory.GetByGroupNameAndCodeAndTitle(AppGlobal.CRM, AppGlobal.Product, product.Title);
                                                                    if (product == null)
                                                                    {
                                                                        product = new Config();
                                                                        product.Initialization(InitType.Insert, RequestUserID);
                                                                        product.GroupName = AppGlobal.CRM;
                                                                        product.Code      = AppGlobal.Product;
                                                                        product.Title     = workSheet.Cells[i, 4].Value.ToString().Trim();
                                                                        _configResposistory.Create(product);
                                                                    }
                                                                    membershipProperty.ProductID = product.ID;
                                                                }

                                                                if (membershipProperty.MembershipID > 0)
                                                                {
                                                                    membershipProperty.Code          = AppGlobal.Product;
                                                                    membershipProperty.ValueContract = valueContract;
                                                                    membershipProperty.DateBegin     = DateTime.Now;
                                                                    membershipProperty.DateEnd       = DateTime.Now;
                                                                    membershipProperty.DateContract  = DateTime.Now;
                                                                    membershipProperty.Address       = model.Address;
                                                                    membershipProperty.Initialization(InitType.Insert, RequestUserID);
                                                                    _membershipPropertyRepository.Create(membershipProperty);
                                                                }
                                                            }
                                                            if (membershipProperty != null)
                                                            {
                                                                Invoice invoice = new Invoice();
                                                                invoice.ContractID = membershipProperty.ID;
                                                                invoice.Year       = viewModel.YearFinance;
                                                                invoice.Month      = viewModel.MonthFinance;
                                                                invoice            = _invoiceRepository.GetByContractIDAndYearAndMonth(invoice.ContractID.Value, invoice.Year.Value, invoice.Month.Value);
                                                                if (invoice == null)
                                                                {
                                                                    invoice            = new Invoice();
                                                                    invoice.ContractID = membershipProperty.ID;
                                                                    invoice.Year       = viewModel.YearFinance;
                                                                    invoice.Month      = viewModel.MonthFinance;
                                                                    invoice.Initialization(InitType.Insert, RequestUserID);
                                                                    invoice.ContractID  = membershipProperty.ID;
                                                                    invoice.Year        = viewModel.YearFinance;
                                                                    invoice.Month       = viewModel.MonthFinance;
                                                                    invoice.DateInvoice = new DateTime(invoice.Year.Value, invoice.Month.Value, 28);
                                                                    invoice.Total       = valueContract;
                                                                    _invoiceRepository.Create(invoice);
                                                                }
                                                                if (invoice != null)
                                                                {
                                                                    InvoiceProperty invoiceProperty = _invoicePropertyRepository.GetByInvoiceIDAndProductID(invoice.ID, membershipProperty.ProductID.Value);
                                                                    if (invoiceProperty == null)
                                                                    {
                                                                        invoiceProperty = new InvoiceProperty();
                                                                        invoiceProperty.Initialization(InitType.Insert, RequestUserID);
                                                                        invoiceProperty.InvoiceID = invoice.ID;
                                                                        invoiceProperty.ProductID = membershipProperty.ProductID;
                                                                        invoiceProperty.UnitID    = AppGlobal.UnitID;
                                                                        invoiceProperty.Quantity  = 1;
                                                                        invoiceProperty.UnitPrice = valueContract;
                                                                        invoiceProperty.Total     = invoiceProperty.Quantity * invoiceProperty.UnitPrice;
                                                                        _invoicePropertyRepository.Create(invoiceProperty);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                result = 1;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
            }
            if (result > 0)
            {
                action     = "Customer";
                controller = "Membership";
            }
            return(RedirectToAction(action, controller, new { ID = result }));
        }