예제 #1
0
        public IActionResult Create(MessageTemplateViewModel viewModel)
        {
            string message = string.Empty;

            string validationErrors = string.Join(",", ModelState.Values.Where(E => E.Errors.Count > 0)
                                                  .SelectMany(E => E.Errors)
                                                  .Select(E => E.ErrorMessage)
                                                  .ToArray());

            if (!ModelState.IsValid)
            {
                return(Json(new { success = false, reason = "Validation Failed. \n" + validationErrors }));
            }

            var obj = _mapper.Map <MessageTemplate>(viewModel);

            if (_messageTemplateService.Save(obj, ref message))
            {
                return(Json(new { success = true, reason = string.Empty }));
            }
            else
            {
                return(Json(new { success = false, reason = message }));
            }
        }
예제 #2
0
        protected override DriverResult Editor(MessageTemplatePart part, IUpdateModel updater, dynamic shapeHelper)
        {
            var viewModel = new MessageTemplateViewModel {
                ExpectedParser = _messageTemplateService.SelectParser(part),
                Layouts        = _messageTemplateService.GetLayouts().Where(x => x.Id != part.Id).ToList()
            };

            if (updater != null)
            {
                if (updater.TryUpdateModel(viewModel, Prefix, null, null))
                {
                    part.Title   = viewModel.Title.TrimSafe();
                    part.Subject = viewModel.Subject.TrimSafe();
                    part.Text    = viewModel.Text;
                    part.Layout  = viewModel.LayoutId != null?_contentManager.Get <MessageTemplatePart>(viewModel.LayoutId.Value) : null;

                    part.IsLayout = viewModel.IsLayout;
                }
            }
            else
            {
                viewModel.Title    = part.Title;
                viewModel.Subject  = part.Subject;
                viewModel.Text     = part.Text;
                viewModel.LayoutId = part.Record.LayoutId;
                viewModel.IsLayout = part.IsLayout;
            }

            return(ContentShape("Parts_MessageTemplate_Edit", () => shapeHelper.EditorTemplate(TemplateName: "Parts/MessageTemplate", Model: viewModel, Prefix: Prefix)));
        }
예제 #3
0
        private async Task <SaveResult> ManageExistingApplicationRoleMessageTemplate(MessageTemplateViewModel model,
                                                                                     ICollection <ApplicationRoleMessageTemplate> currentEntityList,
                                                                                     IQueryable <ApplicationRole> ApplicationRole)
        {
            SaveResult saveResult = new SaveResult
            {
                IsSuccess = true
            };

            List <ApplicationRoleMessageTemplate> assignedApplicationRoleMessageTemplates = new List <ApplicationRoleMessageTemplate>();

            foreach (var record in currentEntityList)
            {
                if (saveResult.IsSuccess)
                {
                    if (!model.RoleIds.Any(a => a == record.ApplicationRoleId))
                    {
                        var deleteApplicationRoleMessageTemplate = await _context.ApplicationRoleMessageTemplate.FindAsync(record.Id);

                        if (saveResult.IsSuccess)
                        {
                            _context.Remove(deleteApplicationRoleMessageTemplate);
                            await _context.SaveChangesAsync();

                            saveResult.IsSuccess = true;
                        }
                    }
                    else
                    {
                        saveResult = await EditEntityAsync(model, record);
                    }
                }
            }
            return(saveResult);
        }
예제 #4
0
        private async Task <bool> AddEntity(MessageTemplateViewModel model,
                                            ICollection <ApplicationRoleMessageTemplate> ApplicationRoleMessageTemplates,
                                            IQueryable <ApplicationRole> ApplicationRoles)
        {
            bool isSaveSuccess = true;
            List <ApplicationRoleMessageTemplate> ApplicationRoleMessageTemplateList = new List <ApplicationRoleMessageTemplate>();

            foreach (var record in model.RoleIds)
            {
                var currentApplicationRole = ApplicationRoles.Any(a => a.Id == record);
                if (currentApplicationRole)
                {
                    ApplicationRoleMessageTemplate ApplicationRoleMessageTemplate = new ApplicationRoleMessageTemplate();
                    ApplicationRoleMessageTemplateList.Add(ApplicationRoleMessageTemplate.ToEntity(record, model.Id, model.SessionUserId));
                }
            }

            if (ApplicationRoleMessageTemplateList.Count > 0)
            {
                await _context.ApplicationRoleMessageTemplate.AddRangeAsync(ApplicationRoleMessageTemplateList);

                await _context.SaveChangesAsync();

                isSaveSuccess = true;
            }

            return(isSaveSuccess);
        }
예제 #5
0
        public IActionResult Create(long Id)
        {
            MessageTemplateViewModel viewModel = null;

            if (Id > 0)
            {
                var obj = _messageTemplateService.GetById(Id);
                viewModel = _mapper.Map <MessageTemplateViewModel>(obj);
            }
            var model = Id == 0 ? new MessageTemplateViewModel() : viewModel;

            return(PartialView(model));
        }
예제 #6
0
        private async Task <SaveResult> EditEntityAsync(MessageTemplateViewModel model,
                                                        ApplicationRoleMessageTemplate record)
        {
            var saveResult = new SaveResult();
            var editApplicationRoleMessageTemplate = await _context.ApplicationRoleMessageTemplate.FindAsync(record.Id);

            editApplicationRoleMessageTemplate.ToEntity(record.ApplicationRoleId, model.Id, model.SessionUserId);

            _context.Update(editApplicationRoleMessageTemplate);
            await _context.SaveChangesAsync();

            saveResult.IsSuccess = true;
            return(saveResult);
        }
 /// <summary>
 /// Convert MessageTemplate Entity  into MessageTemplate Object
 /// </summary>
 ///<param name="model">MessageTemplateViewModel</param>
 ///<param name="MessageTemplateEntity">DataAccess.MessageTemplate</param>
 ///<returns>MessageTemplateViewModel</returns>
 public static MessageTemplateViewModel ToViewModel(
     this DataAccess.MessageTemplate entity,
     MessageTemplateViewModel model)
 {
     model.Subject           = entity.Subject;
     model.Name              = entity.Name;
     model.BccEmailAddresses = entity.BccEmailAddresses;
     model.Body              = entity.Body;
     model.DelayBeforeSend   = entity.DelayBeforeSend;
     model.DelayHours        = entity.DelayHours;
     model.EmailAccountId    = entity.EmailAccountId;
     model.Name              = entity.Name;
     model.FromAddress       = entity.FromAddress;
     model.RoleIds           = entity.ApplicationRoleMessageTemplates.Select(a => a.ApplicationRoleId);
     return(model);
 }
예제 #8
0
        public async Task <SaveResult> SaveEntityList(MessageTemplateViewModel model, MessageTemplate parentEntity)
        {
            SaveResult saveResult = new SaveResult();

            var currentEntities = parentEntity.ApplicationRoleMessageTemplates;

            if (model.RoleIds == null)
            {
                if (currentEntities.Any())
                {
                    var ApplicationRoleMessageTemplateIds = currentEntities.ToList().ToList().Select(b => b.Id);

                    var toDeleteList = _context.ApplicationRoleMessageTemplate.Where(a => ApplicationRoleMessageTemplateIds.Contains(a.Id));

                    _context.ApplicationRoleMessageTemplate.RemoveRange(toDeleteList);
                    await _context.SaveChangesAsync();

                    saveResult.IsSuccess = true;
                }
                else
                {
                    saveResult.IsSuccess = true;
                }
            }
            else
            {
                var regions = _context.ApplicationRole.Where(a => model.RoleIds.Contains(a.Id));

                if (currentEntities.Any())
                {
                    saveResult.IsSuccess = await AddApplicationRoleMessageTemplateWherePreviousExists(model, currentEntities, regions);

                    if (saveResult.IsSuccess)
                    {
                        saveResult = await ManageExistingApplicationRoleMessageTemplate(model, currentEntities, regions);
                    }
                }
                else
                {
                    saveResult.IsSuccess = await AddEntity(model, currentEntities, regions);
                }
            }


            return(saveResult);
        }
        public ActionResult Create(MessageTemplateViewModel model)
        {
            using (var context = new InnostarModelsContext())
            {
                var repository = new MessageTemplateRepository(context);
                var template   = new MessageTemplate
                {
                    Blocked         = false,
                    SpecialTemplate = 0,
                    Message         = model.Text,
                    Title           = model.Title
                };

                repository._Insert(template);
                repository._Save();
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(MessageTemplateViewModel model)
        {
            using (var context = new InnostarModelsContext())
            {
                var repository = new MessageTemplateRepository(context);
                var template   = repository._Get(e => e.Id == model.Id).FirstOrDefault();

                template.Message = model.Text;

                if (!model.Blocked)
                {
                    template.Title = model.Title;
                }

                repository._Update(template);
                repository._Save();
            }

            return(RedirectToAction("Index"));
        }
        /// <summary>
        /// Convert MessageTemplate Object into MessageTemplate Entity
        /// </summary>
        ///<param name="model">MessageTemplate</param>
        ///<param name="MessageTemplateEntity">DataAccess.MessageTemplate</param>
        ///<returns>DataAccess.MessageTemplate</returns>
        public static MessageTemplate ToEntity(this MessageTemplateViewModel model,
                                               MessageTemplate entity)
        {
            if (entity.Id == 0)
            {
                entity.CreatedUserId = model.SessionUserId;
            }
            else
            {
                entity.UpdatedUserId    = model.SessionUserId;
                entity.UpdatedTimestamp = DateTime.Now;
            }
            entity.Subject           = model.Subject;
            entity.Name              = model.Name;
            entity.BccEmailAddresses = model.BccEmailAddresses;
            entity.Body              = model.Body;
            entity.DelayBeforeSend   = model.DelayBeforeSend;
            entity.DelayHours        = model.DelayHours;
            entity.EmailAccountId    = model.EmailAccountId;
            entity.Name              = model.Name;
            entity.FromAddress       = model.FromAddress;

            return(entity);
        }
예제 #12
0
        private async Task <bool> AddApplicationRoleMessageTemplateWherePreviousExists(MessageTemplateViewModel model,
                                                                                       ICollection <ApplicationRoleMessageTemplate> ApplicationRoleMessageTemplates,
                                                                                       IQueryable <ApplicationRole> ApplicationRoles)
        {
            bool isSaveSuccess = true;
            List <ApplicationRoleMessageTemplate> assignedApplicationRoleMessageTemplates = new List <ApplicationRoleMessageTemplate>();

            foreach (var recordId in model.RoleIds)
            {
                var currentRolePermission = ApplicationRoles.Where(a => a.Id == recordId).FirstOrDefault();
                if (currentRolePermission != null)
                {
                    if (!ApplicationRoleMessageTemplates.Any(a => a.ApplicationRoleId == recordId))
                    {
                        // var currentUserRoleID = currentMenuRoles.First(a => a.ApplicationRole.RoleID == currentRolePermission.RoleID).RegionID;
                        var ApplicationRoleMessageTemplateRepo = new ApplicationRoleMessageTemplate();
                        assignedApplicationRoleMessageTemplates.Add(ApplicationRoleMessageTemplateRepo.ToEntity(recordId, model.Id, model.SessionUserId));
                    }
                }
            }

            if (assignedApplicationRoleMessageTemplates.Count > 0)
            {
                await _context.ApplicationRoleMessageTemplate.AddRangeAsync(assignedApplicationRoleMessageTemplates);

                await _context.SaveChangesAsync();

                isSaveSuccess = true;
            }

            return(isSaveSuccess);
        }