Ejemplo n.º 1
0
        public IActionResult Edit(CustomerActionModel model, bool continueEditing)
        {
            CheckValidateModel(model);

            var customeraction = _customerActionService.GetCustomerActionById(model.Id);

            if (customeraction == null)
            {
                return(RedirectToAction("List"));
            }
            try
            {
                if (ModelState.IsValid)
                {
                    customeraction = _customerActionViewModelService.UpdateCustomerActionModel(customeraction, model);
                    SuccessNotification(_localizationService.GetResource("Admin.Customers.CustomerAction.Updated"));
                    return(continueEditing ? RedirectToAction("Edit", new { id = customeraction.Id }) : RedirectToAction("List"));
                }
                _customerActionViewModelService.PrepareReactObjectModel(model);
                return(View(model));
            }
            catch (Exception exc)
            {
                ErrorNotification(exc);
                return(RedirectToAction("Edit", new { id = customeraction.Id }));
            }
        }
        public virtual CustomerAction InsertCustomerActionModel(CustomerActionModel model)
        {
            var customeraction = model.ToEntity();

            _customerActionService.InsertCustomerAction(customeraction);
            _customerActivityService.InsertActivity("AddNewCustomerAction", customeraction.Id, _localizationService.GetResource("ActivityLog.AddNewCustomerAction"), customeraction.Name);
            return(customeraction);
        }
        public static CustomerAction ToEntity(this CustomerActionModel model, CustomerAction destination, IDateTimeService dateTimeService)
        {
            var action = model.MapTo(destination);

            action.StartDateTimeUtc = model.StartDateTime.ConvertToUtcTime(dateTimeService);
            action.EndDateTimeUtc   = model.EndDateTime.ConvertToUtcTime(dateTimeService);
            return(action);
        }
Ejemplo n.º 4
0
        public static CustomerAction ToEntity(this CustomerActionModel model, IDateTimeHelper dateTimeHelper)
        {
            var action = model.MapTo <CustomerActionModel, CustomerAction>();

            action.StartDateTimeUtc = model.StartDateTime.ConvertToUtcTime(dateTimeHelper);
            action.EndDateTimeUtc   = model.EndDateTime.ConvertToUtcTime(dateTimeHelper);
            return(action);
        }
        public virtual async Task <CustomerAction> InsertCustomerActionModel(CustomerActionModel model)
        {
            var customeraction = model.ToEntity(_dateTimeHelper);
            await _customerActionService.InsertCustomerAction(customeraction);

            await _customerActivityService.InsertActivity("AddNewCustomerAction", customeraction.Id, _localizationService.GetResource("ActivityLog.AddNewCustomerAction"), customeraction.Name);

            return(customeraction);
        }
        public virtual CustomerActionModel PrepareCustomerActionModel()
        {
            var model = new CustomerActionModel();

            model.Active         = true;
            model.StartDateTime  = DateTime.Now;
            model.EndDateTime    = DateTime.Now.AddMonths(1);
            model.ReactionTypeId = (int)CustomerReactionTypeEnum.Banner;
            PrepareReactObjectModel(model);
            return(model);
        }
 public async Task<IActionResult> Create(CustomerActionModel model, bool continueEditing)
 {
     CheckValidateModel(model);
     if (ModelState.IsValid)
     {
         var customeraction = await _customerActionViewModelService.InsertCustomerActionModel(model);
         SuccessNotification(_localizationService.GetResource("Admin.Customers.CustomerAction.Added"));
         return continueEditing ? RedirectToAction("Edit", new { id = customeraction.Id }) : RedirectToAction("List");
     }
     await _customerActionViewModelService.PrepareReactObjectModel(model);
     return View(model);
 }
 protected void CheckValidateModel(CustomerActionModel model)
 {
     if ((model.ReactionType == CustomerReactionTypeEnum.Banner) && String.IsNullOrEmpty(model.BannerId))
         ModelState.AddModelError("error", "Banner is required");
     if ((model.ReactionType == CustomerReactionTypeEnum.InteractiveForm) && String.IsNullOrEmpty(model.InteractiveFormId))
         ModelState.AddModelError("error", "Interactive form is required");
     if ((model.ReactionType == CustomerReactionTypeEnum.Email) && String.IsNullOrEmpty(model.MessageTemplateId))
         ModelState.AddModelError("error", "Email is required");
     if ((model.ReactionType == CustomerReactionTypeEnum.AssignToCustomerRole) && String.IsNullOrEmpty(model.CustomerRoleId))
         ModelState.AddModelError("error", "Customer role is required");
     if ((model.ReactionType == CustomerReactionTypeEnum.AssignToCustomerTag) && String.IsNullOrEmpty(model.CustomerTagId))
         ModelState.AddModelError("error", "Tag is required");
 }
        public virtual async Task PrepareReactObjectModel(CustomerActionModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var banners = await _bannerService.GetAllBanners();

            foreach (var item in banners)
            {
                model.Banners.Add(new SelectListItem
                {
                    Text  = item.Name,
                    Value = item.Id.ToString()
                });
            }
            var message = await _messageTemplateService.GetAllMessageTemplates("");

            foreach (var item in message)
            {
                model.MessageTemplates.Add(new SelectListItem
                {
                    Text  = item.Name,
                    Value = item.Id.ToString()
                });
            }
            var customerRole = await _customerService.GetAllCustomerRoles();

            foreach (var item in customerRole)
            {
                model.CustomerRoles.Add(new SelectListItem
                {
                    Text  = item.Name,
                    Value = item.Id.ToString()
                });
            }

            var customerTag = await _customerTagService.GetAllCustomerTags();

            foreach (var item in customerTag)
            {
                model.CustomerTags.Add(new SelectListItem
                {
                    Text  = item.Name,
                    Value = item.Id.ToString()
                });
            }

            foreach (var item in await _customerActionService.GetCustomerActionType())
            {
                model.ActionType.Add(new SelectListItem()
                {
                    Text  = item.Name,
                    Value = item.Id.ToString()
                });
            }

            foreach (var item in await _interactiveFormService.GetAllForms())
            {
                model.InteractiveForms.Add(new SelectListItem()
                {
                    Text  = item.Name,
                    Value = item.Id.ToString()
                });
            }
        }
        public virtual async Task <CustomerAction> UpdateCustomerActionModel(CustomerAction customeraction, CustomerActionModel model)
        {
            if (customeraction.Conditions.Count() > 0)
            {
                model.ActionTypeId = customeraction.ActionTypeId;
            }
            if (String.IsNullOrEmpty(model.ActionTypeId))
            {
                model.ActionTypeId = customeraction.ActionTypeId;
            }

            customeraction = model.ToEntity(customeraction);
            await _customerActionService.UpdateCustomerAction(customeraction);

            await _customerActivityService.InsertActivity("EditCustomerAction", customeraction.Id, _localizationService.GetResource("ActivityLog.EditCustomerAction"), customeraction.Name);

            return(customeraction);
        }
Ejemplo n.º 11
0
 public static CustomerAction ToEntity(this CustomerActionModel model, CustomerAction destination)
 {
     return(model.MapTo(destination));
 }
Ejemplo n.º 12
0
 public static CustomerAction ToEntity(this CustomerActionModel model)
 {
     return(model.MapTo <CustomerActionModel, CustomerAction>());
 }