public void Save(DistributorViewModel distviewmodel)
        {
            bool isNew = false;
            CostCentre distributorCC = _costCentreRepository.GetById(distviewmodel.Id);
            if (distributorCC==null) //then new
            {
                
                isNew = true;
                Producer parentCC = _producerRepository.GetProducer();
                distributorCC = _costCentreFactory.CreateCostCentre(distviewmodel.Id, CostCentreType.Distributor, parentCC);
            }
          

            Distributor distributor = distributorCC as Distributor;
            distributor.CostCentreCode = distviewmodel.CostCentreCode;
            distributor.Name = distviewmodel.Name;
            distributor.Owner = distviewmodel.Owner;
            distributor.Region = _regionrepository.GetById(distviewmodel.RegionId);
            distributor.ASM = distviewmodel.ASM != Guid.Empty  ? _userRepository.GetById(distviewmodel.ASM) : null;
            distributor.SalesRep = distviewmodel.SalesRep != Guid.Empty
                                       ? _userRepository.GetById(distviewmodel.SalesRep)
                                       : null;
            distributor.Surveyor = distviewmodel.Surveyor != Guid.Empty
                                       ? _userRepository.GetById(distviewmodel.Surveyor)
                                       : null;
            distributor.AccountNo = distviewmodel.AccountNo;
            distributor.VatRegistrationNo = distviewmodel.VatRegistrationNo;
            distributor.PIN = distviewmodel.PIN;
            distributor.ProductPricingTier = _pricingTierRepository.GetById(distviewmodel.PricingTierId);
            distributor.PaybillNumber = distviewmodel.PayBillNumber;
            distributor.MerchantNumber = distviewmodel.MerchantNumber;

            Guid distributorId = _distrepository.Save(distributor);

            if (isNew)
            {
                CostCentre savedDistributor = _distrepository.GetById(distributorId);
                
                //also setup a distributor pending dispatchwarehouse
                CostCentre _ccdpdw =
                    _costCentreFactory.CreateCostCentre(Guid.NewGuid(), CostCentreType.DistributorPendingDispatchWarehouse,
                                                        savedDistributor);
                DistributorPendingDispatchWarehouse ccdpdw = _ccdpdw as DistributorPendingDispatchWarehouse;
                ccdpdw.Name = savedDistributor.Name + " - Pending Dispatch Warehouse ";
                _costCentreRepository.Save(ccdpdw);
            }

        }
Ejemplo n.º 2
0
        public ActionResult CreateDistributor(DistributorViewModel dvm)
        {
            try
            {
                ViewBag.RegionList = _DistributorViewModelBuilder.Region();
                _DistributorViewModelBuilder.Save(dvm);
                return RedirectToAction("listDistributors");
            }
            catch (DomainValidationException dve)
            {

                string msg = ValidationSummary.DomainValidationErrors(dve);
                ViewBag.msg = msg;
                return View();
            }
            catch (Exception ex)
            {
                ViewBag.msg = ex.Message;

                return View();
            }

        }
Ejemplo n.º 3
0
 public ActionResult EditDistributor(DistributorViewModel dvm)
 {
     _DistributorViewModelBuilder.Save(dvm);
     ViewBag.RegionList = _DistributorViewModelBuilder.Region();
     return RedirectToAction("listDistributors");
 }
Ejemplo n.º 4
0
        public ActionResult EditDistributor(DistributorViewModel dvm)
        {
            //ViewBag.RegionList = _DistributorViewModelBuilder.Region();
            //ViewBag.ASMList = _DistributorViewModelBuilder.ASM();
            //ViewBag.SalesRepList = _DistributorViewModelBuilder.SalesRep();
            //ViewBag.SurveyorList = _DistributorViewModelBuilder.Surveyor();
            try
            {
                _DistributorViewModelBuilder.Save(dvm);
                _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Edit", "Distributor", DateTime.Now);
                Session["msg"] = "Distributor Successfully Edited";
                return RedirectToAction("listDistributors");
            }
            catch (DomainValidationException dve)
            {
                ValidationSummary.DomainValidationErrors(dve,ModelState);
                _log.Debug("Failed to edit distributor" + dve.Message);
                _log.Error("Failed to edit distributor" + dve.ToString());
                return View();
            }
            catch (Exception ex)
            {
                _log.Debug("Failed to edit distributor" + ex.Message);
                _log.Error("Failed to edit distributor" + ex.ToString());
                HQMailerViewModelBuilder hqm = new HQMailerViewModelBuilder(ConfigurationSettings.AppSettings["ServerIP"], ConfigurationSettings.AppSettings["UserName"], ConfigurationSettings.AppSettings["Password"]);


                hqm.Send(ConfigurationSettings.AppSettings["ServerEmail"], ConfigurationSettings.AppSettings["MailGroup"], "Test", "Edit Distributor error:" + ex.Message);

                return View();
            }

        }
Ejemplo n.º 5
0
        public ActionResult CreateDistributor(DistributorViewModel dvm)
        {
            ViewBag.RegionList = _DistributorViewModelBuilder.Region();
            ViewBag.ASMList = _DistributorViewModelBuilder.ASM();
            ViewBag.SalesRepList = _DistributorViewModelBuilder.SalesRep();
            ViewBag.SurveyorList = _DistributorViewModelBuilder.Surveyor();
            //ViewBag.TierList = _DistributorViewModelBuilder.PricingTier();
            try
            {
                if (dvm.RegionId == Guid.Empty)
                {
                    ModelState.AddModelError("Distributor", "Region is required");
                    return View();
                }
                else
                {
                    dvm.Id = Guid.NewGuid();
                    _DistributorViewModelBuilder.Save(dvm);
                    _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Create", "Distributor", DateTime.Now);
                    Session["msg"] = "Distributor Successfully Created";
                    var latestDistributr = _DistributorViewModelBuilder.Get(dvm.Id);//.Where(n => n.DateCreated < DateTime.Now).OrderByDescending(n => n.DateCreated).ThenByDescending(n => n.id).ToList()[0];//;
                    //  DistributorViewModel  latestDistributr = _DistributorViewModelBuilder.GetAll().FirstOrDefault(n=>n.DateCreated<DateTime.Now);

                    Guid distributrId = latestDistributr.Id;
                    string distributorName = latestDistributr.Name;
                    // return RedirectToAction("listDistributors");
                    return RedirectToAction("CreateContact", "Contact", new { CostCentre = distributrId, CostCentreName = distributorName, ContactFor = "Distributor" });
                }
            }
            catch (DomainValidationException dve)
            {

                ValidationSummary.DomainValidationErrors(dve, ModelState);
                _log.Debug("Failed to create distributor" + dve.Message);
                _log.Error("Failed to create distributor" + dve.ToString());
                return View();
            }
            catch (Exception ex)
            {
                ViewBag.msg = ex.Message;
                _log.Debug("Failed to create distributor" + ex.Message);
                _log.Error("Failed to create distributor" + ex.ToString()); HQMailerViewModelBuilder hqm = new HQMailerViewModelBuilder(ConfigurationSettings.AppSettings["ServerIP"], ConfigurationSettings.AppSettings["UserName"], ConfigurationSettings.AppSettings["Password"]);


                hqm.Send(ConfigurationSettings.AppSettings["ServerEmail"], ConfigurationSettings.AppSettings["MailGroup"], "Test", "Create Distributor error:" + ex.Message);

                return View();
            }

        }
        DistributorViewModel Map(Distributor distributor)
        {
            DistributorViewModel distributorViewModel = new DistributorViewModel();
            distributorViewModel.Id = distributor.Id;
            distributorViewModel.Name = distributor.Name;
            distributorViewModel.Owner = distributor.Owner;
            if (distributor.Region != null)
            {
                distributorViewModel.RegionId = distributor.Region.Id;
                distributorViewModel.RegionName = distributor.Region.Name;
            }


            if (distributor.SalesRep != null)
            {
                distributorViewModel.SalesRepName =_userRepository.GetById(distributor.SalesRep.Id).Username;
            }
            if (distributor.Surveyor != null)
            {
                distributorViewModel.SurveyorName =_userRepository.GetById(distributor.Surveyor.Id).Username;
            }
            if (distributor.ASM != null)
            {
                distributorViewModel.ASMName =_userRepository.GetById( distributor.ASM.Id).Username;
            }

            distributorViewModel.RegionId = distributor.Region == null ? Guid.Empty: distributor.Region.Id;
            distributorViewModel.PricingTierId = distributor.ProductPricingTier == null ? Guid.Empty : distributor.ProductPricingTier.Id;
            distributorViewModel.Region =distributor.Region==null ? "": _regionrepository.GetById(distributor.Region.Id).Name;
            distributorViewModel.AccountNo = distributor.AccountNo;
            distributorViewModel.VatRegistrationNo = distributor.VatRegistrationNo;
            distributorViewModel.PIN = distributor.PIN;
            distributorViewModel.CostCentreCode = distributor.CostCentreCode;
            distributorViewModel.DateCreated = distributor._DateCreated;
            distributorViewModel.PayBillNumber = distributor.PaybillNumber;
            distributorViewModel.MerchantNumber = distributor.MerchantNumber;
            distributorViewModel.ASM = distributor.ASM == null ? Guid.Empty : distributor.ASM.Id;
            distributorViewModel.SalesRep = distributor.SalesRep == null ? Guid.Empty : distributor.SalesRep.Id;
            distributorViewModel.Surveyor = distributor.Surveyor == null ? Guid.Empty : distributor.Surveyor.Id;
            if (distributor.Id == Guid.Empty)
                distributorViewModel.IsActive = true;
            else
                distributorViewModel.IsActive = distributor._Status == EntityStatus.Active ? true : false;

            distributorViewModel.CanEditRegion = _masterDataUsage.CanEditHubOrDistributrRegion(distributor);

            return distributorViewModel;


        }