public ActionResult Create(ApplicationRoleViewModel model)
        {
            try
            {
                CreateViewBagParams();
                if (ModelState.IsValid)
                {
                    ApplicationRole applicationRole = new ApplicationRole
                    {
                        Name = model.Name
                    };
                    var roleResult = RoleManager.Create(applicationRole);
                    if (!roleResult.Succeeded)
                    {
                        ModelState.AddModelError("", roleResult.Errors.First());
                        return(PartialView("_PartialAddEdit", new ApplicationRoleViewModel()));
                    }
                    else
                    {
                        _activityRepo.CreateActivityLog(string.Format("Created Portal Role with Name:{0}", applicationRole.Name), this.GetContollerName(), this.GetContollerName(), User.Identity.GetUserId <Int64>(), applicationRole);

                        _rolePermissionyQuery.ExecuteStoreprocedure("DeletePermissionByRoleID @RoleId", new SqlParameter("RoleId", applicationRole.Id));
                        if (model.SelectedPermissionId != null && model.SelectedPermissionId.Any())
                        {
                            foreach (var permissionId in model.SelectedPermissionId)
                            {
                                _rolePermissionCommand.Insert(new RolePermission()
                                {
                                    RoleId       = applicationRole.Id,
                                    PermissionId = permissionId,
                                });
                                _rolePermissionCommand.SaveChanges();
                            }
                        }
                    }

                    TempData["MESSAGE"] = "Portal Role " + applicationRole.Name + " was successfully created";
                    ModelState.Clear();
                    return(Json(new { success = true }));
                }
                else
                {
                    StringBuilder errorMsg = new StringBuilder();

                    foreach (var modelError in ModelState.Values.SelectMany(modelState => modelState.Errors))
                    {
                        errorMsg.AppendLine(modelError.ErrorMessage);
                        ModelState.AddModelError(string.Empty, modelError.ErrorMessage);
                    }
                    ViewBag.ErrMsg = errorMsg.ToString();
                    return(PartialView("_PartialAddEdit", model));
                }
            }
            catch (Exception exp)
            {
                _log.Error(exp);
                return(View("Error"));
            }
        }
示例#2
0
 public void SendPasswordResetEmail(ApplicationUser mUser, string resetUrl)
 {
     try
     {
         EmailTemplate     emailFormat = _emailTemplateRepositoryQuery.GetAllList(m => m.Code == "F_PASSWORD").SingleOrDefault();
         List <EmailToken> tokenCol    = _emailTokenRepositoryQuery.GetAllList(m => m.EmailCode == emailFormat.Code).ToList();
         foreach (var token in tokenCol)
         {
             if (token.Token.Equals("{Name}"))
             {
                 token.PreviewText = mUser.FirstName + " " + mUser.LastName;
             }
             else if (token.Token.Equals("{Email}"))
             {
                 token.PreviewText = mUser.Email ?? string.Empty;
             }
             else if (token.Token.Equals("{Url}"))
             {
                 token.PreviewText = resetUrl;
             }
         }
         try
         {
             EmailLog mlog = new EmailLog();
             mlog.Receiver         = mUser.Email;
             mlog.Sender           = ExtentionUtility.GetAppSetting("MailFrom");
             mlog.Subject          = "Password Reset Notification";
             mlog.MessageBody      = ExtentionUtility.GeneratePreviewHTML(emailFormat.Body, tokenCol);
             mlog.DateCreated      = mlog.DateToSend = DateTime.Now;
             mlog.IsSent           = mlog.HasAttachment = false;
             mlog.EmailAttachments = new List <EmailAttachment>();
             _emailLogRepositoryCommand.Insert(mlog);
             _emailLogRepositoryCommand.SaveChanges();
         }
         catch (DbEntityValidationException filterContext)
         {
             if (typeof(DbEntityValidationException) == filterContext.GetType())
             {
                 foreach (var validationErrors in filterContext.EntityValidationErrors)
                 {
                     foreach (var validationError in validationErrors.ValidationErrors)
                     {
                         System.Diagnostics.Debug.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                     }
                 }
             }
             throw;
         }
     }
     catch
     {
         throw;
     }
 }
示例#3
0
        public Task SendEmailResetPasswordAsync(string emailcode, ApplicationUser usermodel, string resetUrl)
        {
            if (string.IsNullOrEmpty(emailcode))
            {
                List <EmailToken> emailtoken = new List <EmailToken>();
                var emailTemplate            = _emailTemplateQuery.FirstOrDefault(m => m.Code == emailcode);
                if (emailTemplate.Id > 0)
                {
                    List <EmailToken> tokenCol = _emailTokenQuery.GetAllList(m => m.EmailCode == emailTemplate.Code).ToList();
                    foreach (var token in tokenCol)
                    {
                        if (token.Token.Equals("{Name}"))
                        {
                            token.PreviewText = usermodel.FirstName + " " + usermodel.LastName;
                        }
                        else if (token.Token.Equals("{Email}"))
                        {
                            token.PreviewText = usermodel.Email ?? string.Empty;
                        }
                        else if (token.Token.Equals("{Url}"))
                        {
                            token.PreviewText = resetUrl;
                        }
                    }

                    EmailLog mlog = new EmailLog();
                    mlog.Receiver    = usermodel.Email;
                    mlog.Sender      = _appSettings.EmailFromAddress;
                    mlog.Subject     = "Password Reset Notification";
                    mlog.MessageBody = GeneratePreviewHTML(emailTemplate.Body, tokenCol);
                    mlog.DateCreated = mlog.DateToSend = DateTime.Now;
                    mlog.IsSent      = mlog.HasAttachment = false;
                    var messageresponse = EmailSenderHelper(mlog.Receiver, mlog.Subject, mlog.MessageBody);
                    if (messageresponse.success)
                    {
                        mlog.IsSent = true;
                    }
                    _emailLogRepositoryCommand.Insert(mlog);
                    _emailLogRepositoryCommand.SaveChanges();
                }
            }
            return(Task.CompletedTask);
        }
示例#4
0
 public void CreateActivityLog(string descriptn, string moduleName, string moduleAction, Int64 userid, object record)
 {
     try
     {
         ActivityLog alog = new ActivityLog
         {
             ModuleName   = moduleName,
             ModuleAction = moduleAction,
             UserId       = userid,
             Description  = descriptn,
             Record       = record != null?JsonConvert.SerializeObject(record) : "N/A"
         };
         _activityLogRepositoryCommand.Insert(alog);
         _activityLogRepositoryCommand.SaveChanges();
     }
     catch (Exception ex)
     {
         _log.Error(ex);
     }
 }
示例#5
0
 public void Execute()
 {
     try
     {
         List <EmailLog> emaillogmodellist = _emailJobQuery.GetAllList(m => m.IsSent == false && m.DateToSend <= DateTime.Now).Take(10).ToList();
         if (emaillogmodellist.Any())
         {
             foreach (EmailLog emaillogmodel in emaillogmodellist)
             {
                 try
                 {
                     MailMessage msg    = GenerateMail(emaillogmodel);
                     bool        result = Utilities.EmailHandler.Send(msg);
                     if (result)
                     {
                         emaillogmodel.DateSent = DateTime.Now;
                         emaillogmodel.IsSent   = true;
                     }
                     else
                     {
                         emaillogmodel.IsSent = false;
                         emaillogmodel.Retires++;
                     }
                     _emailJobCommand.Update(emaillogmodel);
                     _emailJobCommand.SaveChanges();
                 }
                 catch (Exception)
                 {
                     throw;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         _log.Info(ex);
         throw;
     }
 }
示例#6
0
        public ActionResult FrameworkSetting(FrameworkSetupViewModel model, string nextButton, string backButton)
        {
            ModelState.Clear();
            _activityRepo.CreateActivityLog("In Framework setting currentconfig", this.ControllerContext.ActionDescriptor.ControllerName, this.ControllerContext.ActionDescriptor.ActionName, 0, null);
            if (backButton != null)
            {
                return(RedirectToAction("CurrentConfig"));
            }

            if (nextButton != null)
            {
                if (!ModelState.IsValid)
                {
                    return(View(_setupContract));
                }

                if (string.IsNullOrEmpty(model.PortalSetting.PortalTitle))
                {
                    ModelState.AddModelError("", "Portal title is required");
                    return(View(_setupContract));
                }

                var app = new Application {
                    ApplicationName = model.PortalSetting.PortalTitle, Description = model.PortalSetting.PortalDescription, TermsAndConditions = model.PortalSetting.TermsAndConditionPath, HasAdminUserConfigured = false
                };
                if (_applicationQuery.GetAll().Any())
                {
                    Application datamodel = _applicationQuery.GetAll().FirstOrDefault();
                    app.Id = datamodel.Id;
                    datamodel.ApplicationName    = app.ApplicationName;
                    datamodel.Description        = app.Description;
                    datamodel.TermsAndConditions = app.TermsAndConditions;
                    _applicationCommand.Update(datamodel);
                }
                else
                {
                    _applicationCommand.Insert(app);
                }
                _applicationCommand.SaveChanges();

                if (app.Id >= 1)
                {
                    _activityRepo.CreateActivityLog("creating Framework application data", this.ControllerContext.ActionDescriptor.ControllerName, this.ControllerContext.ActionDescriptor.ActionName, 0, app);
                    return(RedirectToAction("FramewokAdmin"));
                }
                ModelState.AddModelError("", "Unable to save framework settings due to internal error! Please try again later");
                return(View(_setupContract));
            }
            var application = _applicationQuery.GetAll().FirstOrDefault();
            var portalInfo  = _mapper.Map <PortalSettingViewModel>(application);

            if (portalInfo == null)
            {
                // ModelState.AddModelError("", "Unable to initialize portal information due to internal error! Please try again later");
                return(View(_setupContract));
            }

            _setupContract.PortalSetting = portalInfo;
            return(View(_setupContract));

            //add settings to DB
        }