Beispiel #1
0
        private List <ListCampaignServicesViewModel> GetCampaignServices(CampaignRegisterViewModel model)
        {
            var resultList = new List <ListCampaignServicesViewModel>();

            if (!string.IsNullOrEmpty(model.DeletedServices))
            {
                if (!string.IsNullOrEmpty(model.NewServices))
                {
                    var deleted = model.DeletedServices.Split(';').Where(d => d != string.Empty);
                    foreach (var item in deleted)
                    {
                        model.NewServices = model.NewServices.Replace(";" + item, "");
                    }
                }
            }
            if (!string.IsNullOrEmpty(model.NewServices))
            {
                resultList.AddRange(model.NewServices.Split(';').Where(s => s != string.Empty).Select(item => new ListCampaignServicesViewModel()
                {
                    IdService = Guid.Parse(item)
                }));
            }

            return(resultList);
        }
Beispiel #2
0
        public bool Save(CampaignRegisterViewModel model, Guid accountId)
        {
            var campaign         = ConvertCampaign.FromCampaignRegisterViewModel(model);
            var campaignServices = GetCampaignServices(model);

            SaveCampaign(campaign, campaignServices, accountId);
            return(true);
        }
Beispiel #3
0
        public CampaignRegisterViewModel GetCampaign(Guid idCampaign, Guid idAccount)
        {
            var model = new CampaignRegisterViewModel();

            if (idCampaign != Guid.Empty)
            {
                var campaign = _campaignDao.GetOne(idCampaign, idAccount);
                campaign.CampaignServices = _campaignServicesDao.GetCampaignServicesByCampaign(idCampaign, idAccount);
                foreach (var campaignService in campaign.CampaignServices)
                {
                    campaignService.Service = _serviceDao.GetOne(campaignService.IdService, idAccount);
                }
                model = ConvertCampaign.ToCampaignRegisterViewModel(campaign, model);
            }

            return(model);
        }
Beispiel #4
0
 public IActionResult Register(CampaignRegisterViewModel model)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             GetDropDownListData(model);
             return(View(model));
         }
         _campaignBusiness.Save(model, ApplicationUserCurrent.AccountId);
         return(RedirectToAction("Index"));
     }
     catch (Exception e)
     {
         _logger.LogError(new EventId(0, "Error Index"), e.Message);
         return(RedirectToAction("Index", "StatusCode", new { statusCode = 1 }));
     }
 }
Beispiel #5
0
        private void GetDropDownListData(CampaignRegisterViewModel model)
        {
            var myWatch = new Stopwatch();

            ViewBag.CustomerList =
                _customerBusiness.GetCustomersByAccount(ApplicationUserCurrent.AccountId)
                .Select(s => new SelectListItem()
            {
                Text = s.Name, Value = s.Id.ToString()
            })
                .ToList();

            myWatch.Start();
            ViewBag.StatusList =
                _statusCampaignBusiness.GetStatusCampaigns()
                .Select(s => new SelectListItem()
            {
                Text = s.Name, Value = s.Id.ToString()
            })
                .ToList();
            myWatch.Stop();

            Debugger.Log(0, "Drop", $"ms: {myWatch.ElapsedMilliseconds}");

            ViewBag.SupervisorList =
                _userBusiness.GetUserListByType(CTypePerson.PersonSupervisor, ApplicationUserCurrent.AccountId)
                .Select(s => new SelectListItem()
            {
                Text = s.Profile.Name, Value = s.Id.ToString()
            })
                .ToList();

            ViewBag.ChannelList =
                _channelBusiness.GetChanelListByCustomer(model.IdCustomer, ApplicationUserCurrent.AccountId);

            ViewBag.Services =
                _serviceBusiness.GetServicesByChannelId(ApplicationUserCurrent.AccountId, model.IdChannel)
                .Select(c => new SelectListItem()
            {
                Text = c.Name, Value = c.Id.ToString()
            })
                .ToList();
        }
 public static Campaign FromCampaignRegisterViewModel(CampaignRegisterViewModel model)
 {
     return(new Campaign()
     {
         Id = model.Id,
         IdChannel = model.IdChannel,
         IdCustomer = model.IdCustomer,
         IdStatusCampaign = model.IdStatusCampaign,
         IdSupervisor = model.IdSupervisor,
         Name = model.Name,
         Code = model.Code,
         StartDate = model.StartDate,
         EndDate = model.EndDate,
         CreationDate = model.CreationDate,
         RangeDate = model.RangeDate,
         StatusRegister = CStatusRegister.Active,
         Comment = model.Comment
     });
 }
        public static CampaignRegisterViewModel ToCampaignRegisterViewModel(Campaign campaign, CampaignRegisterViewModel model)
        {
            model.Name             = campaign.Name;
            model.Code             = campaign.Code;
            model.StartDate        = campaign.StartDate;
            model.EndDate          = campaign.EndDate;
            model.CreationDate     = campaign.CreationDate;
            model.RangeDate        = campaign.RangeDate;
            model.Id               = campaign.Id;
            model.IdStatusCampaign = campaign.IdStatusCampaign;
            model.IdCustomer       = campaign.IdCustomer;
            model.IdChannel        = campaign.IdChannel;
            model.IdSupervisor     = campaign.IdSupervisor;
            model.Comment          = campaign.Comment;
            model.ServiceList      = new List <Service>();

            foreach (var cService in campaign.CampaignServices)
            {
                model.ServiceList.Add(cService.Service);
            }

            model.NewServices = model.ServiceList.Aggregate(string.Empty, (x, y) => x + (";" + y.Id.ToString()));

            return(model);
        }