public async Task <ActionResult> PostUserMaster([FromBody] UserMaster userMaster) { try { if (ModelState.IsValid) { if (!UserMasterExists(userMaster.Email, userMaster.EmployeeCode)) { userMaster.LinkExpiryDate = DateTime.Now.AddDays(1); //userMaster.CompanyId = new Guid(HttpContext.Session.GetString("#COMPANY_ID")); userMaster.CompanyId = new Guid(User.Claims.FirstOrDefault(p => p.Type == "CompanyId").Value); _context.UserMaster.Add(userMaster); await _context.SaveChangesAsync(); GenericMethods.Log(LogType.ActivityLog.ToString(), "PostUserMaster: " + userMaster.Email + "-User created successfully"); //CreatedAtAction("GetUserMaster", new { id = userMaster.UserId }, userMaster); #region Email Body for activation string FilePath = _hostingEnvironment.ContentRootPath + "//HTMLTemplate//CreateNewPwd.html"; StreamReader str = new StreamReader(FilePath); string MailText = str.ReadToEnd(); string domain = _configuration.GetSection("Domains").GetSection("CurrentDomain").Value; //string domain = _configuration.GetValue<string>("Domains:CurrentDomain"); MailText = MailText.Replace("#CREATE_PWD_LINK", domain + "/new-pwd/" + userMaster.UserId); #endregion GenericMethods.SendEmailNotification(userMaster.Email, "OmniCRM User activation link", MailText); return(Ok(StatusCodes.Status200OK)); } else { return(Conflict("User already exist!")); } } else { return(BadRequest("Failed to create user!")); } } catch (Exception ex) { GenericMethods.Log(LogType.ErrorLog.ToString(), "PostUserMaster: " + ex.ToString()); return(StatusCode(StatusCodes.Status500InternalServerError, ex)); } }
public async Task <IActionResult> ForgotPassword(string id) { try { if (!UserMasterExists(id, "")) { GenericMethods.Log(LogType.ActivityLog.ToString(), "ForgotPassword: "******"-not found"); return(this.NotFound("Email address does not exist.")); } var objUser = await _context.UserMaster.FirstOrDefaultAsync(p => p.Email == id); if (objUser != null && objUser.Status == true) { objUser.LinkExpiryDate = DateTime.Now.AddDays(1); _context.Entry(objUser).State = EntityState.Modified; await _context.SaveChangesAsync(); #region Email Body for activation string FilePath = _hostingEnvironment.ContentRootPath + "//HTMLTemplate//CreateNewPwd.html"; StreamReader str = new StreamReader(FilePath); string MailText = str.ReadToEnd(); string domain = _configuration.GetSection("Domains").GetSection("CurrentDomain").Value; //string domain = _configuration.GetValue<string>("Domains:CurrentDomain"); MailText = MailText.Replace("#CREATE_PWD_LINK", domain + "/new-pwd/" + objUser.UserId); #endregion GenericMethods.SendEmailNotification(objUser.Email, "OmniCRM Create New Password Link", MailText); GenericMethods.Log(LogType.ActivityLog.ToString(), "ForgotPassword: "******"-create password link sent"); return(this.Ok("Reset password link sent on your mail. Please check your email account.")); } else { GenericMethods.Log(LogType.ActivityLog.ToString(), "ForgotPassword: "******"-user is not active"); return(this.NotFound("User is not active.")); } } catch (Exception ex) { GenericMethods.Log(LogType.ErrorLog.ToString(), "ForgotPassword: " + ex.ToString()); return(this.BadRequest(ex.Message)); } }
public async Task <ActionResult> PostCompanyMaster([FromBody] CompanyMaster companyMaster) { try { if (ModelState.IsValid) { if (!UserMasterExists(companyMaster.UserMaster.FirstOrDefault().Email)) { _context.CompanyMaster.Add(companyMaster); await _context.SaveChangesAsync(); #region Email Body for activation string FilePath = _hostingEnvironment.ContentRootPath + "//HTMLTemplate//CreateNewPwd.html"; StreamReader str = new StreamReader(FilePath); string MailText = str.ReadToEnd(); string domain = _configuration.GetSection("Domains").GetSection("CurrentDomain").Value; //string domain = _configuration.GetValue<string>("Domains:CurrentDomain"); MailText = MailText.Replace("#CREATE_PWD_LINK", domain + "/new-pwd/" + companyMaster.UserMaster.FirstOrDefault().UserId); #endregion GenericMethods.SendEmailNotification(companyMaster.UserMaster.FirstOrDefault().Email, "OmniCRM User activation link", MailText); GenericMethods.Log(LogType.ActivityLog.ToString(), "PostCompanyMaster: " + companyMaster.CompanyName + "-Company created successfully"); return(Ok(StatusCodes.Status200OK)); } else { return(Conflict("Email id already exist!")); } } else { return(BadRequest("Failed to create company!")); } } catch (Exception ex) { GenericMethods.Log(LogType.ErrorLog.ToString(), "PostCompanyMaster: " + ex.ToString()); return(StatusCode(StatusCodes.Status500InternalServerError, ex)); } }
public async Task <ActionResult <UserMaster> > AddUserMaster(UserMaster userMaster) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (_context.UserMaster.FirstOrDefault(p => p.UserName.ToLower() == userMaster.UserName.ToLower()) != null) { return(Conflict("User Name already exists")); } _context.UserMaster.Add(userMaster); await _context.SaveChangesAsync(); List <string> ToEmails = new List <string>(); ToEmails.Add(userMaster.UserName); GenericMethods.SendEmailNotification(ToEmails, "User Activation Link", "This is test from user master"); return(CreatedAtAction("GetUserMaster", new { id = userMaster.UserId }, userMaster)); }