コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
0
        public static ApplicationRoleMessageTemplate ToEntity(this ApplicationRoleMessageTemplate entity, string referralId, int containerId, string sessionUserId)
        {
            if (entity.Id > 0)
            {
                entity.UpdatedUserId    = sessionUserId;
                entity.UpdatedTimestamp = DateTime.Now;
            }
            else
            {
                entity.MessageTemplateId = containerId;
                entity.ApplicationRoleId = referralId;
                entity.CreatedUserId     = sessionUserId;
            }



            return(entity);
        }