Beispiel #1
0
        public ActionResult Save(BusinessCreateViewModel model)
        {
            if (BusinessQueries.CheckExistBusiness(UserQueries.GetCurrentUsername(), model.Name))
            {
                ModelState.AddModelError("CheckExistBusiness", "Kinh doanh này đã tồn tại, vui lòng nhập tên khác");
            }

            if (ModelState.IsValid)
            {
                model.Liabilities = (BusinessLiabilityListCreateViewModel)HttpContext.Session["LIABILITIES"];
                string user   = UserQueries.GetCurrentUsername();
                int    result = BusinessQueries.CreateBusiness(model, user);
                if (result > 0)
                {
                    return(Content("success"));
                }
                else
                {
                    return(Content("failed"));
                }
            }
            else
            {
                model.IsInDebt = false;
                return(PartialView("_BusinessForm", model));
            }
        }
        public static int CreateBusiness(BusinessCreateViewModel model, string username)
        {
            int      result   = 0;
            DateTime current  = DateTime.Now;
            Entities entities = new Entities();

            //Create business
            Assets business = new Assets();

            business.AssetName   = model.Name;
            business.Value       = model.Value.Value;
            business.StartDate   = current;
            business.CreatedDate = current;
            business.CreatedBy   = Constants.Constants.USER;
            business.AssetType   = (int)Constants.Constants.ASSET_TYPE.BUSINESS;
            business.ObtainedBy  = (int)Constants.Constants.OBTAIN_BY.CREATE;
            business.Username    = username;

            if (model.Income.HasValue && model.Income.Value > 0)
            {
                //Create income
                Incomes income = new Incomes();
                income.Name        = "Thu nhập kinh doanh từ " + business.AssetName;
                income.Value       = model.Income.Value;
                income.IncomeDay   = 1;
                income.StartDate   = current;
                income.CreatedDate = current;
                income.CreatedBy   = Constants.Constants.USER;
                income.IncomeType  = (int)Constants.Constants.INCOME_TYPE.BUSINESS_INCOME;
                income.Username    = username;
                business.Incomes1.Add(income);
            }

            if (model.IsInDebt)
            {
                if (model.Liabilities != null && model.Liabilities.Liabilities.Count > 0)
                {
                    foreach (var liabilityViewModel in model.Liabilities.Liabilities)
                    {
                        Liabilities liability = new Liabilities();
                        liability.Name             = liabilityViewModel.Source;
                        liability.Value            = liabilityViewModel.Value.Value;
                        liability.InterestType     = liabilityViewModel.InterestType;
                        liability.InterestRate     = liabilityViewModel.InterestRate.Value;
                        liability.InterestRatePerX = liabilityViewModel.InterestRatePerX;
                        liability.StartDate        = liabilityViewModel.StartDate.Value;
                        liability.EndDate          = liabilityViewModel.EndDate.Value;
                        liability.LiabilityType    = (int)Constants.Constants.LIABILITY_TYPE.BUSINESS;
                        liability.CreatedDate      = current;
                        liability.CreatedBy        = Constants.Constants.USER;
                        liability.Username         = username;
                        business.Liabilities.Add(liability);
                    }
                }
            }

            entities.Assets.Add(business);
            result = entities.SaveChanges();
            return(result);
        }
        // GET: Businesses/Create
        public IActionResult Create()
        {
            ViewData["OwnerID"] = User.FindFirstValue(ClaimTypes.NameIdentifier);
            BusinessCreateViewModel vm = new BusinessCreateViewModel();

            return(View(vm));
        }
Beispiel #4
0
        public ActionResult _Create(BusinessCreateViewModel model)
        {
            BusinessLiabilityListCreateViewModel liabilities = (BusinessLiabilityListCreateViewModel)HttpContext.Session["LIABILITIES"];
            double totalLiabilityValue = 0;

            if (liabilities != null)
            {
                totalLiabilityValue = liabilities.Liabilities.Sum(x => x.Value.HasValue ? x.Value.Value : 0);
            }

            if (BusinessQueries.CheckExistBusiness(UserQueries.GetCurrentUsername(), model.Name))
            {
                ModelState.AddModelError("CheckExistBusiness", "Kinh doanh này đã tồn tại, vui lòng nhập tên khác");
            }

            if (model.Value < totalLiabilityValue && totalLiabilityValue > 0)
            {
                ModelState.AddModelError("CompareBusinessValueAndLiabilityValue", "Giá trị tổng số nợ không vượt quá giá trị góp vốn kinh doanh");
            }

            if (ModelState.IsValid)
            {
                HttpContext.Session["BUSINESS"] = model;
                return(Content("success"));
            }
            else
            {
                return(PartialView("_BusinessForm", model));
            }
        }
Beispiel #5
0
        public ActionResult _LiabilityUpdateForm(BusinessLiabilityCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                BusinessLiabilityListCreateViewModel liabilities = (BusinessLiabilityListCreateViewModel)HttpContext.Session["LIABILITIES"];
                BusinessLiabilityCreateViewModel     updateModel = liabilities.Liabilities.Where(x => x.Id == model.Id).FirstOrDefault();

                updateModel.Value = model.Value;

                BusinessCreateViewModel business = (BusinessCreateViewModel)HttpContext.Session["BUSINESS"];
                double totalLiabilityValue       = liabilities != null?liabilities.Liabilities.Sum(x => x.Value.HasValue?x.Value.Value : 0) : 0;

                if (business.Value < totalLiabilityValue && totalLiabilityValue > 0)
                {
                    ModelState.AddModelError("CompareBusinessValueAndLiabilityValue", "Giá trị tổng số nợ không vượt quá giá trị góp vốn kinh doanh");
                    return(PartialView(model));
                }
                else
                {
                    updateModel.Id                     = model.Id;
                    updateModel.Source                 = model.Source;
                    updateModel.InterestType           = model.InterestType;
                    updateModel.InterestRate           = model.InterestRate;
                    updateModel.StartDate              = model.StartDate;
                    updateModel.EndDate                = model.EndDate;
                    HttpContext.Session["LIABILITIES"] = liabilities;
                    return(Content("success"));
                }
            }
            else
            {
                return(PartialView(model));
            }
        }
Beispiel #6
0
        public ActionResult _Create()
        {
            BusinessCreateViewModel model = new BusinessCreateViewModel();

            HttpContext.Session["LIABILITIES"] = null;
            HttpContext.Session["BUSINESS"]    = null;
            return(PartialView(model));
        }
Beispiel #7
0
        public ActionResult _BusinessForm()
        {
            BusinessCreateViewModel model = (BusinessCreateViewModel)HttpContext.Session["BUSINESS"];

            if (model == null)
            {
                model = new BusinessCreateViewModel();
            }
            return(PartialView(model));
        }
        public IActionResult Create(BusinessCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var business = new Business
                {
                    OwnerID      = User.FindFirstValue(ClaimTypes.NameIdentifier),
                    Name         = model.Name,
                    Street       = model.Street,
                    HouseNumber  = model.HouseNumber,
                    Mailbox      = model.Mailbox,
                    Zipcode      = model.Zipcode,
                    City         = model.City,
                    Type         = model.Type,
                    Omschrijving = model.Omschrijving
                };

                if (model.DisplayPicture != null)
                {
                    using (var ms = new MemoryStream())
                    {
                        model.DisplayPicture.CopyTo(ms);
                        business.DisplayPicture = ms.ToArray();
                    }
                }

                var social = model.Social;
                social.Business   = business;
                social.BusinessID = business.ID;

                _businessManager.CreateBusiness(business);
                _socialManager.CreateSocial(social);

                if ((model.MenuID != null) && model.MenuID.Value > 0)
                {
                    var busMenu = new BusinessMenu
                    {
                        BusinessID = business.ID,
                        MenuID     = model.MenuID.Value
                    };
                    _businessMenuManager.CreateBusinessMenu(busMenu);
                }


                foreach (BusinessHour hour in model.BusinessHours)
                {
                    hour.BusinessID = business.ID;
                    _businessManager.AddBusinessHours(hour);
                }

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["OwnerID"] = User.FindFirstValue(ClaimTypes.NameIdentifier);
            return(View(model));
        }
        public ActionResult Create()
        {
            BusinessCreateViewModel businessViewModel = new BusinessCreateViewModel()
            {
                MenuProductGroups = baseViewModel.GetMenu(),
                MenuServiceGroups = baseViewModel.GetMenuServices(),
                FooterRecentBlog  = baseViewModel.GetFooterRecentBlog()
            };

            ViewBag.PackageId = new SelectList(db.Packages.Where(current => current.IsActive), "Id", "Title");

            return(View(businessViewModel));
        }
        public ActionResult Create(BusinessCreateViewModel business)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    bool isValidMobile = Regex.IsMatch(business.CellNumber, @"(^(09|9)[0123456789][0123456789]\d{7}$)|(^(09|9)[0123456789][0123456789]\d{7}$)", RegexOptions.IgnoreCase);

                    if (!isValidMobile)
                    {
                        ModelState.AddModelError("invalidMobile", "شماره موبایل وارد شده صحیح نمی باشد");
                    }

                    else
                    {
                        User user = InsertUser(business.FullName, business.CellNumber);
                        db.SaveChanges();
                        Guid businessId = InsertBusiness(user.Id, business.Email, business.InstagramPage, business.Type, business.PackageId,
                                                         business.Description);

                        db.SaveChanges();

                        return(RedirectToAction("Activate", new { id = user.Code, businessCode = businessId }));
                    }
                }

                business.MenuProductGroups = baseViewModel.GetMenu();
                business.MenuServiceGroups = baseViewModel.GetMenuServices();
                business.FooterRecentBlog  = baseViewModel.GetFooterRecentBlog();
                ViewBag.PackageId          = new SelectList(db.Packages.Where(current => current.IsActive), "Id", "Title");


                return(View(business));
            }
            catch (Exception e)
            {
                BusinessCreateViewModel businessViewModel = new BusinessCreateViewModel()
                {
                    MenuProductGroups = baseViewModel.GetMenu(),
                    MenuServiceGroups = baseViewModel.GetMenuServices(),
                    FooterRecentBlog  = baseViewModel.GetFooterRecentBlog()
                };
                ViewBag.PackageId = new SelectList(db.Packages.Where(current => current.IsActive), "Id", "Title");

                return(View(businessViewModel));
            }
        }
Beispiel #11
0
        public ActionResult _LiabilityForm(BusinessLiabilityCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                int id = 1;
                BusinessLiabilityListCreateViewModel liabilities = (BusinessLiabilityListCreateViewModel)HttpContext.Session["LIABILITIES"];
                BusinessCreateViewModel business = (BusinessCreateViewModel)HttpContext.Session["BUSINESS"];
                double totalLiabilityValue       = liabilities != null?liabilities.Liabilities.Sum(x => x.Value.HasValue?x.Value.Value : 0) : 0;

                if (business.Value < totalLiabilityValue + model.Value && totalLiabilityValue + model.Value > 0)
                {
                    ModelState.AddModelError("CompareBusinessValueAndLiabilityValue", "Giá trị tổng số nợ không vượt quá giá trị góp vốn kinh doanh");
                    return(PartialView(model));
                }
                else
                {
                    if (liabilities == null)
                    {
                        liabilities = new BusinessLiabilityListCreateViewModel();
                    }
                    else
                    {
                        if (liabilities.Liabilities.Count > 0)
                        {
                            id = liabilities.Liabilities.Max(x => x.Id) + 1;
                        }
                        else
                        {
                            id = 1;
                        }
                    }
                    model.Id = id;
                    liabilities.Liabilities.Add(model);
                    HttpContext.Session["LIABILITIES"] = liabilities;
                    return(Content("success"));
                }
            }
            else
            {
                return(PartialView(model));
            }
        }
Beispiel #12
0
 public static long SaveBusiness(BusinessCreateViewModel model)
 {
     try
     {
         using (var context = new IdeaValidationContext())
         {
             var data = new Business()
             {
                 BusinessName         = model.BusinessName,
                 BusinessType         = model.BusinessType,
                 CategoryID           = model.CategoryID,
                 CategoryName         = model.CategoryName,
                 CreatedBy            = model.CreatedBy,
                 CreatedDate          = DateTime.UtcNow,
                 DataSourceName       = model.DataSourceName,
                 EmailID              = model.EmailID,
                 IncorporationDate    = model.IncorporationDate,
                 YearOfIncorporation  = model.YearOfIncorporation,
                 NoOfEmployees        = model.NoOfEmployees,
                 RegisteredCountry    = model.RegisteredCountry,
                 RegisteredCountryID  = model.RegisteredCountryID,
                 RegisteredProvince   = model.RegisteredProvince,
                 RegisteredProvinceID = model.RegisteredProvinceID,
                 RegistrationNumber   = model.RegistrationNumber,
                 Status  = model.Status,
                 Tags    = model.Tags,
                 Website = model.Website
             };
             context.Businesses.Add(data);
             context.SaveChanges();
             return(data.ID);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #13
0
        public ActionResult _Confirm()
        {
            DateTime current = DateTime.Now;

            BusinessCreateViewModel model     = (BusinessCreateViewModel)HttpContext.Session["BUSINESS"];
            BusinessViewModel       viewModel = new BusinessViewModel();

            viewModel.Name         = model.Name;
            viewModel.Value        = model.Value.Value;
            viewModel.Income       = model.Income.HasValue ? model.Income.Value : 0;
            viewModel.AnnualIncome = viewModel.Income * 12;
            viewModel.RentYield    = viewModel.AnnualIncome / viewModel.Value;

            BusinessLiabilityListCreateViewModel liabilities = (BusinessLiabilityListCreateViewModel)HttpContext.Session["LIABILITIES"];

            viewModel.RowSpan = liabilities != null && liabilities.Liabilities.Count > 0 ? liabilities.Liabilities.Count() + 3 : 2;

            if (liabilities != null && liabilities.Liabilities.Count > 0)
            {
                foreach (var liability in liabilities.Liabilities)
                {
                    BusinessLiabilityViewModel liabilityViewModel = new BusinessLiabilityViewModel();
                    liabilityViewModel.Source           = liability.Source;
                    liabilityViewModel.Value            = liability.Value;
                    liabilityViewModel.InterestType     = Helper.GetInterestType(liability.InterestType);
                    liabilityViewModel.InterestRatePerX = Helper.GetInterestTypePerX(liability.InterestRatePerX);
                    liabilityViewModel.InterestRate     = liability.InterestRate / 100;
                    liabilityViewModel.StartDate        = liability.StartDate.Value;
                    liabilityViewModel.EndDate          = liability.EndDate.Value;
                    liabilityViewModel.PaymentPeriod    = Helper.CalculateTimePeriod(liabilityViewModel.StartDate.Value, liabilityViewModel.EndDate.Value);

                    if (liabilityViewModel.StartDate <= current && current <= liabilityViewModel.EndDate)
                    {
                        int    currentPeriod = Helper.CalculateTimePeriod(liabilityViewModel.StartDate.Value, DateTime.Now);
                        double interestRate  = liability.InterestRatePerX == (int)Constants.Constants.INTEREST_RATE_PER.MONTH ? liability.InterestRate.Value / 100 : liability.InterestRate.Value / 1200;
                        liabilityViewModel.OriginalInterestPayment = liabilityViewModel.Value.Value * interestRate;
                        //Fixed interest type
                        if (liability.InterestType == (int)Constants.Constants.INTEREST_TYPE.FIXED)
                        {
                            liabilityViewModel.MonthlyOriginalPayment = liabilityViewModel.Value.Value / liabilityViewModel.PaymentPeriod;
                            liabilityViewModel.MonthlyInterestPayment = liabilityViewModel.Value.Value * interestRate;
                            liabilityViewModel.TotalMonthlyPayment    = liabilityViewModel.MonthlyOriginalPayment + liabilityViewModel.MonthlyInterestPayment;
                            liabilityViewModel.TotalPayment           = RealEstateLiabilityQueries.Helper.CalculateAnnualPayment(liability);
                            liabilityViewModel.RemainedValue          = liabilityViewModel.Value.Value - liabilityViewModel.MonthlyOriginalPayment * (currentPeriod + 1);
                            liabilityViewModel.Status     = "Đang nợ";
                            liabilityViewModel.StatusCode = "label-success";
                        }
                        //Reduced interest type
                        else
                        {
                            liabilityViewModel.MonthlyOriginalPayment = liabilityViewModel.Value.Value / liabilityViewModel.PaymentPeriod;
                            liabilityViewModel.RemainedValue          = liabilityViewModel.Value.Value - liabilityViewModel.MonthlyOriginalPayment * (currentPeriod + 1);
                            liabilityViewModel.MonthlyInterestPayment = (liabilityViewModel.Value.Value - liabilityViewModel.MonthlyOriginalPayment * currentPeriod) * interestRate;
                            liabilityViewModel.TotalMonthlyPayment    = liabilityViewModel.MonthlyOriginalPayment + liabilityViewModel.MonthlyInterestPayment;
                            liabilityViewModel.TotalPayment           = RealEstateLiabilityQueries.Helper.CalculateAnnualPayment(liability);
                            liabilityViewModel.Status     = "Đang nợ";
                            liabilityViewModel.StatusCode = "label-success";
                        }
                    }
                    else
                    {
                        liabilityViewModel.MonthlyOriginalPayment = 0;
                        liabilityViewModel.MonthlyInterestPayment = 0;
                        liabilityViewModel.TotalMonthlyPayment    = 0;
                        liabilityViewModel.TotalPayment           = 0;
                        liabilityViewModel.RemainedValue          = 0;
                    }

                    viewModel.Liabilities.Add(liabilityViewModel);
                }

                var liabilitites = viewModel.Liabilities.Where(x => x.StartDate <= current && x.EndDate >= current);
                viewModel.TotalLiabilityValue  = liabilitites.Select(x => x.Value.Value).DefaultIfEmpty(0).Sum();
                viewModel.TotalOriginalPayment = liabilitites.Select(x => x.MonthlyOriginalPayment).DefaultIfEmpty(0).Sum();
                viewModel.TotalInterestPayment = liabilitites.Select(x => x.MonthlyInterestPayment).DefaultIfEmpty(0).Sum();
                viewModel.TotalMonthlyPayment  = liabilitites.Select(x => x.TotalMonthlyPayment).DefaultIfEmpty(0).Sum();
                viewModel.TotalPayment         = liabilitites.Select(x => x.TotalPayment).DefaultIfEmpty(0).Sum();
                viewModel.TotalRemainedValue   = liabilitites.Select(x => x.RemainedValue).DefaultIfEmpty(0).Sum();
                viewModel.TotalInterestRate    = viewModel.TotalLiabilityValue > 0 ? liabilitites.Select(x => x.OriginalInterestPayment).DefaultIfEmpty(0).Sum() / viewModel.TotalLiabilityValue * 12 : 0;
            }

            return(PartialView(viewModel));
        }