Пример #1
0
 public SettingCMSModel()
 {
     HomepageCMSModel = new HomepageCMSModel();
     GenericIntroducingSettingModel = new GenericIntroducingSettingModel();
     ContactCMSModel = new ContactCMSModel();
     InvestmentTargetSettingModel = new ListInvestmentTargetSettingModel();
     ListWithdrawFee    = new ListWithdrawFee();
     ListMaintainingFee = new ListMaintainingFee();
     HasError           = false;
 }
Пример #2
0
        public ListMaintainingFee GetConfiguration()
        {
            try
            {
                List <MaintainingFee> modelDTO = _maintainingFeeManager.GetConfiguration();
                var list = _mapper.Map <List <MaintainingFeeModel> >(modelDTO);

                ListMaintainingFee item = new ListMaintainingFee();
                item.ListFees = list;
                return(item);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public IActionResult ReturnWithError(ListMaintainingFee model)
        {
            SettingCMSModel settingCMSModel = new SettingCMSModel();

            settingCMSModel.ListMaintainingFee = model;
            settingCMSModel.ListWithdrawFee    = _withdrawFeeService.GetConfiguration().Result;
            settingCMSModel.InvestmentTargetSettingModel.ListModels = _investmentTargetCMSService.GetAll();
            settingCMSModel.ContactCMSModel = _contactConfigurationService.GetContactConfiguration();
            settingCMSModel.GenericIntroducingSettingModel  = _introducingSettingService.GetSetting();
            settingCMSModel.HomepageCMSModel.HomepageModels = _homepageCMSService.GetAll();
            ViewBag.ListPortfolio = _portfolioService.GetAllPortfolio().ToList();
            ViewBag.Data          = _investmentTargetCMSService.GetAll().ToList();
            //settingCMSModel.HasError = true;
            //TempData["ErrorData"] = settingCMSModel;
            //return RedirectToAction("Index", "SettingsCMS");
            return(View("Views/SettingsCMS/Index.cshtml", settingCMSModel));
        }
        //public async Task<IActionResult> Edit([FromBody]ListMaintainingFee model)
        public async Task <IActionResult> Edit(ListMaintainingFee model)
        {
            List <MaintainingFeeModel> newFees     = new List <MaintainingFeeModel>();
            List <MaintainingFeeModel> existedFees = new List <MaintainingFeeModel>();
            bool isValid = true;

            foreach (var item in model.ListFees)
            {
                if (item.AmountTo == 0)
                {
                    TempData["Error"] = Model.Resources.ValidationMessages.DataIsEmpty;
                    return(ReturnWithError(model));
                }
                if (item.AmountFrom >= item.AmountTo)
                {
                    isValid           = false;
                    TempData["Error"] = Model.Resources.ValidationMessages.CompareAmountFromAmountTo;
                    return(ReturnWithError(model));
                }
                else
                {
                    var dataExisted = CheckDataExisted(item.Id);
                    if (!dataExisted)
                    {
                        newFees.Add(item);
                    }
                    else
                    {
                        existedFees.Add(item);
                    }
                }
            }
            if (newFees.Count > 0)
            {
                var listNewFee = newFees;
                //addtional test in case of empty database then database should check validation while data in "newFees list"
                foreach (var item in newFees)
                {
                    listNewFee = newFees.Where(x => (x.AmountFrom != item.AmountFrom || x.AmountTo != item.AmountTo || x.Percentage != item.Percentage)).ToList();

                    var result = listNewFee.Where(x => (item.AmountFrom >= x.AmountFrom && item.AmountTo <= x.AmountTo) ||
                                                  (item.AmountFrom >= x.AmountFrom && item.AmountFrom <= x.AmountTo && item.AmountTo > x.AmountTo) ||
                                                  (item.AmountFrom < x.AmountFrom && item.AmountTo >= x.AmountFrom && item.AmountTo <= x.AmountTo) ||
                                                  (item.AmountFrom <x.AmountFrom && item.AmountTo> x.AmountTo)).ToList();
                    if (result.Count > 0 || result.Any())
                    {
                        TempData["Error"] = Model.Resources.ValidationMessages.RangeAmountExisted;
                        isValid           = false;
                    }
                }
                if (!isValid)
                {
                    return(ReturnWithError(model));
                }
                await _maintainingFeeService.AddListFees(newFees);
            }
            if (existedFees.Count > 0)
            {
                await _maintainingFeeService.UpdateConfigurations(existedFees);
            }
            return(RedirectToAction("Index", "SettingsCMS"));
        }