/// <summary> /// Retrieve a new instance of a subdistributor contract, setting the initial information (discount type, last contract amounts, etc) /// </summary> /// <param name="id">Subdistributor id</param> /// <returns></returns> public ContractSubdistributor InitializeNew(int id) { ResultManager.Clear(); ContractSubdistributor item = null; try { PSD.Controller.SubdistributorController subdistributorController = new Controller.SubdistributorController(Configurations); item = ContractSubdistributor.NewEmpty(); item.Subdistributor = subdistributorController.RetrieveSubdistributor(id); item.SubdistributorId = id; item.RegisteredRegionName = item.Subdistributor.BNAddress.AddressColony.AddressPostalCode.AddressMunicipality.Zone.RegionName; item.RegisteredZoneName = item.Subdistributor.BNAddress.AddressColony.AddressPostalCode.AddressMunicipality.Zone.Name; //set discount type (for benefits program->coupons->discountTable) ContractSubdistributor auxLastContract = Repository.ContractsSubdistributor.GetPastYearSubdistributorContract(id); if (auxLastContract == null) {//first contract item.DiscountType = 0; } else {//contract renovation item.DiscountType = auxLastContract.DiscountType + 1; } ResultManager.IsCorrect = true; } catch (Exception ex) { ResultManager.Add(ErrorDefault, Trace + "InitializeNew.511 Excepción al inicializar el nuevo elemento" + ex.Message); } return(item); }
public ActionResult Create(ContractSubdistributor model, List <int> selectedDistributors = null) { if (model == null) { NotifyUser(messageError: errorDefault, messageDebug: "No se recibió el modelo"); } else { if (selectedDistributors == null) { NotifyUser(messageError: "Se debe seleccionar al menos un distribuidor", messageDebug: "No se recibió el parámetro 'selectedDistributors'"); } else { //fill in selected distributors in model model.DistributorPurchases = new List <DistributorPurchasesXContractSubdistributor>(); foreach (int item in selectedDistributors) { model.DistributorPurchases.Add(new DistributorPurchasesXContractSubdistributor() { ContractSubdistributorId = model.Id, DistributorId = item }); } if (controller.Create(model, true) || controller.ResultManager.IsCorrect) { NotifyUser(resultManager: controller.ResultManager); return(RedirectToAction("Index")); } } } PSD.Controller.DistributorController distributorController = new Controller.DistributorController(Configurations); ViewBag.AvailableDistributors = GetDistributors(distributorController.GetSubdistributorZones(model.Id)); PSD.Controller.SubdistributorController subdistributorController = new Controller.SubdistributorController(Configurations); model.Subdistributor = subdistributorController.RetrieveSubdistributor(model.SubdistributorId); model.SubdistributorId = model.SubdistributorId; NotifyUser(resultManager: controller.ResultManager); return(View(model)); }
public ActionResult RegisterPurchase(ContractSubdistributor model, int selectedMonth = -1, decimal purchaseAmount = 0) { if (model == null) { NotifyUser(messageError: errorDefault, messageDebug: "No se recibió el modelo"); } else { if (selectedMonth == -1) { NotifyUser(messageError: "Se debe seleccionar el mes", messageDebug: "No se recibió el parámetro 'selectedDistributors'"); } else { if (purchaseAmount == 0) { NotifyUser(messageError: "El monto no puede ser cero", messageDebug: "No se recibió el parámetro 'selectedDistributors'"); } else { if (controller.RegisterPurchase(model, selectedMonth, purchaseAmount) && controller.ResultManager.IsCorrect) { NotifyUser(messageOk: "La compra ha sido registrada"); return(RedirectToAction("Index")); } } } } PSD.Controller.DistributorController distributorController = new Controller.DistributorController(Configurations); ViewBag.AvailableDistributors = GetDistributors(distributorController.GetSubdistributorZones(model.Id)); PSD.Controller.SubdistributorController subdistributorController = new Controller.SubdistributorController(Configurations); model.Subdistributor = subdistributorController.RetrieveSubdistributor(model.SubdistributorId); model.SubdistributorId = model.SubdistributorId; ViewBag.CanRegisterS1 = Configurations.BenefitProgram_Coupon_S1_IsOpen; ViewBag.CanRegisterS2 = Configurations.BenefitProgram_Coupon_S1_IsOpen; NotifyUser(resultManager: controller.ResultManager); return(View(model)); }
public SubdistributorController() : base("SubdistributorController") { controller = new Controller.SubdistributorController(Configurations); }