Ejemplo n.º 1
0
        public ActionResult DistributorCreate()
        {
            ViewBag.AddressStates = AddressStates();
            DistributorEmployee newEmployee = DistributorEmployee.NewEmpty();

            TempData["CropsXMunicipality"] = null;
            return(View(newEmployee));
        }
Ejemplo n.º 2
0
        public ActionResult EditDistributorEmployee()
        {
            ViewBag.AddressStates = AddressStates();
            DistributorEmployee employee = controller.GetDistributorEmployee(CurrentUser.Id);

            if (employee.Distributor.CropsXMunicipality != null)
            {
                TempData["CropsXMunicipality"] = employee.Distributor.CropsXMunicipality;
            }
            return(View(employee));
        }
Ejemplo n.º 3
0
        public ActionResult Edit(int Id)
        {
            ViewBag.AddressStates = AddressStates();
            PSD.Controller.AccountController accountController = new PSD.Controller.AccountController(Configurations);
            DistributorEmployee employee = accountController.GetDistributorEmployee(Id);

            if (employee.Distributor.CropsXMunicipality != null)
            {
                TempData["CropsXMunicipality"] = employee.Distributor.CropsXMunicipality;
            }
            return(View(employee));
        }
        public bool SendToDistributor(int id)
        {
            ResultManager.IsCorrect = false;
            //initial validations
            //-sys validations
            //-business validations
            if (id < 1)
            {
                ResultManager.Add(ErrorDefault, Trace + "SendToDistributor.111 No se recibio el parámetro id");
                return(false);
            }

            //update status to 4: review-distributor
            ContractDistributor auxContract = null;

            try
            {
                auxContract = Repository.ContractsDistributor.Get(id);
                auxContract.ContractDistributorStatusId = 4;

                Repository.Complete();
                ResultManager.IsCorrect = true;
            }
            catch (Exception ex)
            {
                ResultManager.Add(ErrorDefault, Trace + "SendToDistributor.511 Excepción al actualizar el elemento" + ex.Message);
            }

            if (ResultManager.IsCorrect)
            {
                ResultManager.Add("El convenio ha sido actualizado", "");
                try
                {
                    //send email to subdistributor
                    DistributorEmployee auxDistributorEmployee = Repository.Distributors.Get(id).DistributorUsers.FirstOrDefault();
                    if (SendEmailToDistributorRequestApproval(auxDistributorEmployee.NameDisplay, auxDistributorEmployee.EMail, auxDistributorEmployee.Distributor.CurrentContract.Id, auxDistributorEmployee.Distributor.CurrentContract.IdB))
                    {
                        ResultManager.Add("Se ha enviado un correo al distribuidor", "");
                    }
                    else
                    {
                        ResultManager.Add("No se pudo enviar actualización por correo al distribuidor");
                    }
                }
                catch (Exception ex)
                {
                    ResultManager.Add(ErrorDefault, Trace + "Create.511 Excepción al crear el convenio: " + ex.Message);
                }
            }

            return(ResultManager.IsCorrect);
        }
        public bool Approve(int contractId)
        {
            ResultManager.IsCorrect = false;
            //initial validations
            //-sys validations
            if (contractId == -1)
            {
                ResultManager.Add(ErrorDefault, Trace + "Approve.111 No se recibio el parámetro id");
                return(false);
            }
            //-business validations

            //approve
            int auxDistributorId            = -1;
            ContractDistributor auxContract = null;

            try
            {
                auxContract = Repository.ContractsDistributor.Get(contractId);
                auxContract.ContractDistributorStatusId = 3;

                auxDistributorId = auxContract.DistributorId;

                Repository.Complete();
                ResultManager.IsCorrect = true;
            }
            catch (Exception ex)
            {
                ResultManager.Add(ErrorDefault, Trace + "Approve.511 Excepción al crear el nuevo elemento" + ex.Message);
            }

            if (ResultManager.IsCorrect)
            {
                ResultManager.Add("El convenio ha sido actualizado", "");
                DistributorEmployee auxDistributorEmployee = Repository.Distributors.Get(auxDistributorId).DistributorUsers.FirstOrDefault();
                if (SendEmailContractApproved(auxDistributorEmployee.NameDisplay, auxDistributorEmployee.EMail, contractId, auxContract.IdB))
                {
                    ResultManager.Add("Se ha enviado un correo al distribuidor", "");
                }
                else
                {
                    ResultManager.Add("No se pudo enviar actualización por correo al distribuidor");
                }
            }

            return(ResultManager.IsCorrect);
        }
Ejemplo n.º 6
0
        public ActionResult DistributorCreate(DistributorEmployee model, string postAction = "", int selectedAddressState = -1, List <int> selectedMunicipalities = null, List <int> selectedCrops = null)
        {
            if (model == null)
            {
                return(RedirectToError(messageDebug: controllerTraceId + "DistributorCreate[Post].111 No model was received"));
            }

            if (TempData["CropsXMunicipality"] != null)
            {
                //copy the info from TempData into an aux object (cause we cannot use the same object from TempData, it would cause to have two UnitOfWork objects (one from the TempDate and one from the controller object), causing an error on the controller
                ICollection <DistributorCropsXMunicipality> auxCropsXMunicipality = (ICollection <DistributorCropsXMunicipality>)TempData["CropsXMunicipality"];
                foreach (DistributorCropsXMunicipality item in auxCropsXMunicipality)
                {
                    model.Distributor.CropsXMunicipality.Add(new DistributorCropsXMunicipality()
                    {
                        AddressMunicipalityAddressStateId = item.AddressMunicipalityAddressStateId,
                        AddressMunicipalityId             = item.AddressMunicipalityId,
                        Cat_CropId = item.Cat_CropId,
                        //Crop = item.Crop,
                        //Municipality = item.Municipality
                    });
                }
                auxCropsXMunicipality          = null;
                TempData["CropsXMunicipality"] = model.Distributor.CropsXMunicipality;
            }

            List <AddressMunicipality> auxMunicipalities;

            switch (postAction)
            {
            case "getMunicipalities":     //get municipalities for the selected addressState
                auxMunicipalities = controller.GetMunicipalitiesByState(selectedAddressState);
                //ViewBag.SelectedPostalCode = auxPostalCode;
                ViewBag.AvailableMunicipalities = auxMunicipalities;
                ViewBag.AddressStates           = AddressStates(selectedAddressState);
                return(View(model));

            case "addInfluence":     //add "area de influencia" to the list
                auxMunicipalities = controller.GetMunicipalitiesByState(selectedAddressState);
                foreach (int itemMunicipalityId in selectedMunicipalities)
                {
                    foreach (int itemCropId in selectedCrops)
                    {
                        AddressMunicipality municipalityName = new AddressMunicipality();
                        foreach (AddressMunicipality aMName in auxMunicipalities)
                        {
                            if (aMName.Id == itemMunicipalityId)
                            {
                                municipalityName = aMName;
                                break;
                            }
                        }

                        model.Distributor.CropsXMunicipality.Add(new DistributorCropsXMunicipality()
                        {
                            AddressMunicipalityAddressStateId = selectedAddressState
                            ,
                            Crop = controller.GetCropById(itemCropId)
                            ,
                            AddressMunicipalityId = itemMunicipalityId
                            ,
                            Municipality = municipalityName
                            ,
                            Cat_CropId = itemCropId
                            ,
                            DistributorId = model.DistributorId
                        });
                        TempData["CropsXMunicipality"] = model.Distributor.CropsXMunicipality;
                    }
                }
                ViewBag.AddressStates = AddressStates();
                return(View(model));

            case "createDistributor":
                if (controller.CreateDistributor(model) && controller.ResultManager.IsCorrect)
                {
                    NotifyUser(messageOk: controller.ResultManager.ToDescriptionString(), messageDebug: controllerTraceId + "EmployeeCreate.831 employee created", resultDetails: controller.ErrorManager.ToStringList());
                    return(RedirectToAction("Index"));
                }
                break;

            default:
                break;
            }
            ViewBag.AddressStates = AddressStates();
            NotifyUser(messageError: controller.ResultManager.ToDescriptionString(), messageDebug: controllerTraceId + "EmployeeCreate.811", resultDetails: controller.ErrorManager.ToStringList());
            return(View(model));
        }
Ejemplo n.º 7
0
        public ActionResult Edit(DistributorEmployee model, string postAction = "", int selectedAddressState = -1, List <int> selectedMunicipalities = null, List <int> selectedCrops = null)
        {
            if (model == null)
            {
                return(RedirectToError(messageDebug: controllerTraceId + "DistributorCreate[Post].111 No model was received"));
            }

            if (TempData["CropsXMunicipality"] != null)
            {
                model.Distributor.CropsXMunicipality = (ICollection <DistributorCropsXMunicipality>)TempData["CropsXMunicipality"];
                TempData["CropsXMunicipality"]       = model.Distributor.CropsXMunicipality;
            }

            List <AddressMunicipality> auxMunicipalities;

            switch (postAction)
            {
            case "getMunicipalities":     //get municipalities for the selected addressState
                auxMunicipalities = controller.GetMunicipalitiesByState(selectedAddressState);
                //ViewBag.SelectedPostalCode = auxPostalCode;
                ViewBag.AvailableMunicipalities = auxMunicipalities;
                ViewBag.AddressStates           = AddressStates(selectedAddressState);
                model.Distributor.Address       = controller.Repository.Addresses.Get((int)model.Distributor.AddressId);
                return(View(model));

            case "addInfluence":     //add "area de influencia" to the list
                auxMunicipalities = controller.GetMunicipalitiesByState(selectedAddressState);
                foreach (int itemMunicipalityId in selectedMunicipalities)
                {
                    foreach (int itemCropId in selectedCrops)
                    {
                        AddressMunicipality municipalityName = new AddressMunicipality();
                        foreach (AddressMunicipality aMName in auxMunicipalities)
                        {
                            if (aMName.Id == itemMunicipalityId)
                            {
                                municipalityName = aMName;
                                break;
                            }
                        }

                        model.Distributor.CropsXMunicipality.Add(new DistributorCropsXMunicipality()
                        {
                            AddressMunicipalityAddressStateId = selectedAddressState
                            ,
                            Crop = controller.GetCropById(itemCropId)
                            ,
                            AddressMunicipalityId = itemMunicipalityId
                            ,
                            Municipality = municipalityName
                            ,
                            Cat_CropId = itemCropId
                            ,
                            DistributorId = model.DistributorId
                        });
                        TempData["CropsXMunicipality"] = model.Distributor.CropsXMunicipality;
                    }
                }
                ViewBag.AddressStates     = AddressStates();
                model.Distributor.Address = controller.Repository.Addresses.Get((int)model.Distributor.AddressId);
                return(View(model));

            case "updateDistributor":
                PSD.Controller.AccountController accountController = new PSD.Controller.AccountController(Configurations);
                if (accountController.UpdateDistributorEmployee(model) && accountController.ResultManager.IsCorrect)
                {
                    NotifyUser(messageOk: accountController.ResultManager.ToDescriptionString(), messageDebug: controllerTraceId + "EmployeeCreate.831 distributor updated", resultDetails: controller.ErrorManager.ToStringList());
                    return(RedirectToAction("Index"));
                }
                break;

            default:
                break;
            }
            ViewBag.AddressStates     = AddressStates();
            model.Distributor.Address = controller.Repository.Addresses.Get((int)model.Distributor.AddressId);
            NotifyUser(messageError: controller.ResultManager.ToDescriptionString(), messageDebug: controllerTraceId + "EmployeeCreate.811", resultDetails: controller.ErrorManager.ToStringList());
            return(View(model));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Retrieve DistributorId data
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public int GetDistributorId(int userId)
        {
            DistributorEmployee employeeData = Repository.DistributorEmployees.Get(userId);

            return(employeeData.DistributorId);
        }
        public bool Update(ContractDistributor model, bool sendToDistributorReview)
        {
            ResultManager.IsCorrect = false;
            //initial validations
            //-sys validations
            if (model == null)
            {
                ResultManager.Add(ErrorDefault, Trace + "Update.111 No se recibio el modelo");
                return(false);
            }
            //-business validations

            /*if (string.IsNullOrWhiteSpace(model.IdB))
             * {
             *  ResultManager.Add("El id del convenio no puede estar vacio");
             *  return false;
             * }
             * if (model.DistributorId == 0 || model.DistributorId == -1)
             * {
             *  ResultManager.Add("El nombre del cultivo no puede estar vacio");
             *  return false;
             * }
             * if (model.GRVBayerEmployeeId == 0 || model.GRVBayerEmployeeId == -1)
             * {
             *  ResultManager.Add("Se debe tener asignado un GRV");
             *  return false;
             * }
             * if (model.RTVBayerEmployeeId == 0 || model.RTVBayerEmployeeId == -1)
             * {
             *  ResultManager.Add("Se debe tener asignado un RTV");
             *  return false;
             * }
             * if (model.Year == 0 || model.Year == -1)
             * {
             *  ResultManager.Add("Se debe indicar el año del convenio");
             *  return false;
             * }
             * if (string.IsNullOrWhiteSpace(model.RegisteredZoneName))
             * {
             *  ResultManager.Add("Debe haber una zona asignada");
             *  return false;
             * }
             * if (model.AmountGoalQ1Pre == 0 || model.AmountGoalQ1Pre == -1)
             * {
             *  ResultManager.Add("El monto Q1 no puede estar vacio");
             *  return false;
             * }
             * if (model.AmountGoalQ2Pre == 0 || model.AmountGoalQ2Pre == -1)
             * {
             *  ResultManager.Add("El monto Q2 no puede estar vacio");
             *  return false;
             * }
             * if (model.AmountGoalQ3Pre == 0 || model.AmountGoalQ3Pre == -1)
             * {
             *  ResultManager.Add("El monto Q3 no puede estar vacio");
             *  return false;
             * }
             * if (model.AmountGoalQ4Pre == 0 || model.AmountGoalQ4Pre == -1)
             * {
             *  ResultManager.Add("El monto Q4 no puede estar vacio");
             *  return false;
             * }*/
            if (model.AmountGoalTotalPre == 0 || model.AmountGoalTotalPre == -1)
            {
                ResultManager.Add("El total de monto meta no puede estar vacio");
                return(false);
            }

            //update item
            try
            {
                ContractDistributor auxContract = Repository.ContractsDistributor.Get(model.Id);

                auxContract.AmountGoalQ1       = auxContract.AmountGoalQ1Pre = model.AmountGoalQ1Pre;
                auxContract.AmountGoalQ2       = auxContract.AmountGoalQ2Pre = model.AmountGoalQ2Pre;
                auxContract.AmountGoalQ3       = auxContract.AmountGoalQ3Pre = model.AmountGoalQ3Pre;
                auxContract.AmountGoalQ4       = auxContract.AmountGoalQ4Pre = model.AmountGoalQ4Pre;
                auxContract.AmountGoalTotalPre = auxContract.AmountGoalTotal = model.AmountGoalTotalPre;

                //auxContract.ContractFilePath = string.Empty;

                if (sendToDistributorReview)
                {
                    auxContract.ContractDistributorStatusId = 4;
                }

                Repository.Complete();
                ResultManager.IsCorrect = true;
            }
            catch (Exception ex)
            {
                ResultManager.Add(ErrorDefault, Trace + "Update.511 Excepción al crear el nuevo elemento" + ex.Message);
            }

            if (ResultManager.IsCorrect)
            {
                ResultManager.Add("El convenio ha sido actualizado", "");
                if (sendToDistributorReview)
                {
                    DistributorEmployee auxDistributorEmployee = Repository.Distributors.Get(model.DistributorId).DistributorUsers.FirstOrDefault();
                    if (SendEmailToDistributorContractUpdated(auxDistributorEmployee.NameDisplay, auxDistributorEmployee.EMail, model.Id, model.IdB))
                    {
                        ResultManager.Add("Se ha enviado un correo al distribuidor", "");
                    }
                    else
                    {
                        ResultManager.Add("No se pudo enviar actualización por correo al distribuidor");
                    }
                }
            }

            return(ResultManager.IsCorrect);
        }
        public bool Create(ContractDistributor model, bool sendToDistributorReview)
        {
            ResultManager.IsCorrect = false;
            //initial validations
            //-sys validations
            if (model == null)
            {
                ResultManager.Add(ErrorDefault, Trace + "Create.111 No se recibio el modelo");
                return(false);
            }
            //-business validations
            if (model.DistributorId == 0 || model.DistributorId == -1)
            {
                ResultManager.Add("Se debe seleccionar un distribuidor");
                return(false);
            }

            /*
             * if (model.GRVBayerEmployeeId == 0 || model.GRVBayerEmployeeId == -1)
             * {
             *  ResultManager.Add("Se debe tener asignado un GRV");
             *  return false;
             * }
             * if (model.RTVBayerEmployeeId == 0 || model.RTVBayerEmployeeId == -1)
             * {
             *  ResultManager.Add("Se debe tener asignado un RTV");
             *  return false;
             * }
             */
            if (model.Year == 0 || model.Year == -1)
            {
                ResultManager.Add("Se debe indicar el año del convenio");
                return(false);
            }
            if (string.IsNullOrWhiteSpace(model.RegisteredZoneName))
            {
                ResultManager.Add("Debe haber una zona asignada");
                return(false);
            }

            /*deprecated: it can be some of these are not available
             * if (model.AmountGoalQ1Pre == 0 || model.AmountGoalQ1Pre == -1)
             * {
             *  ResultManager.Add("El monto Q1 no puede estar vacio");
             *  return false;
             * }
             * if (model.AmountGoalQ2Pre == 0 || model.AmountGoalQ2Pre == -1)
             * {
             *  ResultManager.Add("El monto Q2 no puede estar vacio");
             *  return false;
             * }
             * if (model.AmountGoalQ3Pre == 0 || model.AmountGoalQ3Pre == -1)
             * {
             *  ResultManager.Add("El monto Q3 no puede estar vacio");
             *  return false;
             * }
             * if (model.AmountGoalQ4Pre == 0 || model.AmountGoalQ4Pre == -1)
             * {
             *  ResultManager.Add("El monto Q4 no puede estar vacio");
             *  return false;
             * }
             */
            if (model.AmountGoalTotalPre == 0 || model.AmountGoalTotalPre == -1)
            {
                ResultManager.Add("El total de monto meta no puede estar vacio");
                return(false);
            }

            //insert new item
            try
            {
                ContractDistributor newContract = new ContractDistributor();

                newContract.IdB = Repository.AppConfigurations.IdBCounterGetNextContractDistributor();
                newContract.GRVBayerEmployeeId   = CurrentUser.Id;
                newContract.RTVBayerEmployeeId   = CurrentUser.Id;
                newContract.RegisteredZoneName   = model.RegisteredZoneName;
                newContract.RegisteredRegionName = model.RegisteredRegionName;
                newContract.Year               = model.Year;
                newContract.AmountGoalQ1       = newContract.AmountGoalQ1Pre = model.AmountGoalQ1Pre;
                newContract.AmountGoalQ2       = newContract.AmountGoalQ2Pre = model.AmountGoalQ2Pre;
                newContract.AmountGoalQ3       = newContract.AmountGoalQ3Pre = model.AmountGoalQ3Pre;
                newContract.AmountGoalQ4       = newContract.AmountGoalQ4Pre = model.AmountGoalQ4Pre;
                newContract.AmountGoalTotalPre = newContract.AmountGoalTotal = model.AmountGoalTotalPre;

                //default values
                newContract.ContractDate     = Common.Dates.Today;
                newContract.ContractFilePath = string.Empty;

                if (sendToDistributorReview)
                {
                    newContract.ContractDistributorStatusId = 4;//4:revision distribuidor
                }
                else
                {
                    newContract.ContractDistributorStatusId = 3;//3:revision bayer
                }

                //relate contract as current distributor contract
                newContract.DistributorId = model.DistributorId;
                newContract.Distributor   = Repository.Distributors.Get(newContract.DistributorId);
                if (newContract.Distributor.CurrentContract == null)
                {//first contract
                    newContract.DiscountType = 0;
                }
                else
                {//contract renovation
                    newContract.DiscountType = 1;
                }
                newContract.Distributor.CurrentContract = newContract;
                //distributorController = null;//release so we can call main Repository.Complete

                Repository.ContractsDistributor.Add(newContract);
                Repository.Complete();
                ResultManager.IsCorrect = true;
            }
            catch (Exception ex)
            {
                ResultManager.Add(ErrorDefault, Trace + "Create.511 Excepción al crear el nuevo elemento", ex);
            }

            if (ResultManager.IsCorrect)
            {
                ResultManager.Add("El convenio ha sido actualizado", "");
                try
                {
                    //send email to subdistributor
                    DistributorEmployee auxDistributorEmployee = Repository.Distributors.Get(model.DistributorId).DistributorUsers.FirstOrDefault();
                    if (SendEmailToDistributorRequestApproval(auxDistributorEmployee.NameDisplay, auxDistributorEmployee.EMail, auxDistributorEmployee.Distributor.CurrentContract.Id, auxDistributorEmployee.Distributor.CurrentContract.IdB))
                    {
                        ResultManager.Add("Se ha enviado un correo al distribuidor", "");
                    }
                    else
                    {
                        ResultManager.Add("No se pudo enviar actualización por correo al distribuidor");
                    }
                }
                catch (Exception ex)
                {
                    ResultManager.Add(ErrorDefault, Trace + "Create.511 Excepción al crear el convenio: " + ex.Message);
                }
            }

            return(ResultManager.IsCorrect);
        }
Ejemplo n.º 11
0
        public bool UpdateDistributorEmployee(DistributorEmployee model)
        {
            if (model == null)
            {
                return(false);
            }

            if (IsMailAddressCurrentlyUsed(model.EMail, model.Id))
            {
                ResultManager.Add(ErrorDefault, Trace + "La direccion de email '" + model.EMail + "' actualmente esta asignada a otro usuario, por favor ingresa una diferente.");
                return(false);
            }

            DistributorEmployee auxEmployee = null;

            try
            {
                auxEmployee = Repository.DistributorEmployees.Get(model.Id);
                auxEmployee.User.NickName = model.EMail;
                auxEmployee.EMail         = model.EMail;
                //auxEmployee.Name = model.Name;
                //auxEmployee.LastNameF = model.LastNameF;
                //auxEmployee.LastNameM = model.LastNameM;
                //auxEmployee.PhoneNumber = model.PhoneNumber;

                //auxEmployee.Distributor.IdB = model.Distributor.IdB;
                auxEmployee.Distributor.BusinessName   = model.Distributor.BusinessName;
                auxEmployee.Distributor.CommercialName = model.Distributor.CommercialName;
                auxEmployee.Distributor.WebSite        = model.Distributor.WebSite;

                //-address
                AddressColony auxColony = Repository.AddressColonies.Get((int)model.Distributor.Address.AddressColonyId);
                auxEmployee.Distributor.Address.AddressStateId        = auxColony.AddressStateId;
                auxEmployee.Distributor.Address.AddressMunicipalityId = auxColony.AddressMunicipalityId;
                auxEmployee.Distributor.Address.AddressPostalCodeId   = auxColony.AddressPostalCodeId;
                auxEmployee.Distributor.Address.AddressColonyId       = auxColony.Id;
                auxEmployee.Distributor.Address.Street    = model.Distributor.Address.Street;
                auxEmployee.Distributor.Address.NumberExt = model.Distributor.Address.NumberExt;
                auxEmployee.Distributor.Address.NumberInt = model.Distributor.Address.NumberInt;


                //if profile was not completed, complete
                if (auxEmployee.User.Cat_UserStatusId == 5)
                {
                    auxEmployee.User.Cat_UserStatusId = 1;
                }

                Repository.Complete();
                ResultManager.Add("Perfil actualizado", "");
                ResultManager.IsCorrect = true;
                return(true);
            }
            catch (Exception ex)
            {
                //Repository.Dispose();
                ErrorManager.Add("", ErrorDefault, "", ex);
                ResultManager.Add(ErrorDefault, "");
                ResultManager.IsCorrect = false;
            }

            return(false);
        }