/// <summary> /// This method is used for insert new contact person of supplier in database. - JJ /// </summary> /// <param name="contactPerson">object of SupplierProfileAC </param> /// <returns>object of SupplierContactPerson </returns> public SupplierContactPerson SaveContactPerson(ContactPersonAC contactPerson) { try { var contactPersons = new SupplierContactPerson { SupplierId = contactPerson.SupplierId, ContactNameEn = contactPerson.ContactNameEn, ContactNameSl = contactPerson.ContactNameSl, JobTitleEn = contactPerson.JobTitleEn, JobTitleSl = contactPerson.JobTitleSl, ContactAddressEn = contactPerson.ContactAddressEn, ContactAddressSl = contactPerson.ContactAddressSl, ContactPhone = contactPerson.ContactPhone, PhoneExtension = contactPerson.PhoneExtension, ContactFax = contactPerson.ContactFax, ContactEmail = contactPerson.ContactEmail, ContactIsDeleted = contactPerson.ContactIsDeleted, CreatedDateTime = DateTime.UtcNow }; _supplierContactPersonContext.Add(contactPersons); _supplierContactPersonContext.SaveChanges(); contactPerson.ContactId = contactPersons.Id; return(contactPersons); } catch (Exception ex) { _errorLog.LogException(ex); throw; } }
public async Task <IActionResult> OnPostAsync() { ReturnUrl = Url.Content("~/"); if (ModelState.IsValid) { if (User.Identity.IsAuthenticated) { await _signInManager.SignOutAsync(); _logger.LogInformation("User logged out."); } var user = new ApplicationUser { UserName = Input.Email, Email = Input.Email }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var UserManager = _serviceProvider.GetRequiredService <UserManager <ApplicationUser> >(); var RoleManager = _serviceProvider.GetRequiredService <RoleManager <ApplicationRole> >(); var roleResult = await RoleManager.FindByNameAsync("Supplier"); if (roleResult == null) { roleResult = new ApplicationRole("Supplier"); await RoleManager.CreateAsync(roleResult); } await UserManager.AddToRoleAsync(user, "Supplier"); FuelSupplier fuelSupplier = new FuelSupplier(); fuelSupplier.UserId = user.Id; fuelSupplier.Name = Input.Name; fuelSupplier.CountryId = Input.CountryId; fuelSupplier.IsMiddler = Input.IsMiddler; if (Input.file != null) { FileInfo fi = new FileInfo(Input.file.FileName); var newFilename = "P" + fuelSupplier.Id + "_" + string.Format("{0:d}", (DateTime.Now.Ticks / 10) % 100000000) + fi.Extension; var webPath = _hostingEnvironment.WebRootPath; var path = Path.Combine("", webPath + @"\uploads\suppliers\" + newFilename); var pathToSave = @"/uploads/suppliers/" + newFilename; using (var stream = new FileStream(path, FileMode.Create)) { await Input.file.CopyToAsync(stream); } fuelSupplier.ImageUrl = pathToSave; } SupplierContact supplierContact1 = new SupplierContact(); supplierContact1.ContactId = 3; supplierContact1.Value = Input.CompanyWebSite; SupplierContact supplierContact2 = new SupplierContact(); supplierContact2.ContactId = 18; supplierContact2.Value = _context.Country.Find(Input.CountryId) != null? _context.Country.Find(Input.CountryId).Name : ""; fuelSupplier.SupplierContact = new List <SupplierContact>(); fuelSupplier.SupplierContact.Add(supplierContact1); fuelSupplier.SupplierContact.Add(supplierContact2); SupplierContactPerson supplierContactPerson = new SupplierContactPerson(); supplierContactPerson.JobTitle = Input.Position; supplierContactPerson.Name = Input.Name; SupplierContactPersonContact supplierContactPersonContact = new SupplierContactPersonContact(); supplierContactPersonContact.ContactId = 7; supplierContactPersonContact.Value = Input.Email; supplierContactPerson.SupplierContactPersonContact = new List <SupplierContactPersonContact>(); supplierContactPerson.SupplierContactPersonContact.Add(supplierContactPersonContact); fuelSupplier.SupplierContactPerson = new List <SupplierContactPerson>(); fuelSupplier.SupplierContactPerson.Add(supplierContactPerson); _context.FuelSupplier.Add(fuelSupplier); _context.SaveChanges(); var contentAppName = _context.ContentManagement.Where(cm => cm.Name == "app_name") .FirstOrDefault(); string AppName = contentAppName == null ? "Fuel Services" : contentAppName.DisplayName; var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { userId = user.Id, code = code }, protocol: Request.Scheme); EmailBodyDefaultParams emailBodyDefaultParams = _context.EmailBodyDefaultParams .Where(e => e.EmailTypeName == "confirm_mail").FirstOrDefault(); string body = EmailSender.CreateEmailBody(emailBodyDefaultParams); body = body.Replace("{callbackurl}", HtmlEncoder.Default.Encode(callbackUrl)); var simpleResponse = EmailSender.SendEmail(Input.Email, AppName, body); TempData.Set("Toast", simpleResponse); return(LocalRedirect(ReturnUrl)); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
public async Task <JsonResult> SupplierRegister([FromBody] SupplierRegisterModel model) { try { if (ModelState.IsValid) { if (User.Identity.IsAuthenticated) { await SignInManager.SignOutAsync(); Serilog.Log.Information("User logged out."); } var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { Serilog.Log.Information("User created a new account with password."); var roleResult = await RoleManager.FindByNameAsync("Supplier"); if (roleResult == null) { roleResult = new ApplicationRole() { Name = "Supplier" }; await RoleManager.CreateAsync(roleResult); } await UserManager.AddToRoleAsync(user, "Supplier"); FuelSupplier fuelSupplier = new FuelSupplier(); fuelSupplier.UserId = user.Id; fuelSupplier.Name = model.Name; fuelSupplier.CountryId = model.CountryId; fuelSupplier.IsMiddler = model.IsMiddler; if (model.file != null) { FileInfo fi = new FileInfo(model.file.FileName); var newFilename = "P" + fuelSupplier.Id + "_" + string.Format("{0:d}", (DateTime.Now.Ticks / 10) % 100000000) + fi.Extension; var webPath = _hostingEnvironment.WebRootPath; var path = Path.Combine("", webPath + @"\uploads\suppliers\" + newFilename); var pathToSave = @"/uploads/suppliers/" + newFilename; using (var stream = new FileStream(path, FileMode.Create)) { await model.file.CopyToAsync(stream); } fuelSupplier.ImageUrl = pathToSave; } SupplierContact supplierContact1 = new SupplierContact(); supplierContact1.ContactId = 3; supplierContact1.Value = model.CompanyWebSite; SupplierContact supplierContact2 = new SupplierContact(); supplierContact2.ContactId = 18; supplierContact2.Value = db.Country.Find(model.CountryId) != null? db.Country.Find(model.CountryId).Name : ""; fuelSupplier.SupplierContact = new List <SupplierContact>(); fuelSupplier.SupplierContact.Add(supplierContact1); fuelSupplier.SupplierContact.Add(supplierContact2); SupplierContactPerson supplierContactPerson = new SupplierContactPerson(); supplierContactPerson.JobTitle = model.Position; supplierContactPerson.Name = model.Name; SupplierContactPersonContact supplierContactPersonContact = new SupplierContactPersonContact(); supplierContactPersonContact.ContactId = 7; supplierContactPersonContact.Value = model.Email; supplierContactPerson.SupplierContactPersonContact = new List <SupplierContactPersonContact>(); supplierContactPerson.SupplierContactPersonContact.Add(supplierContactPersonContact); fuelSupplier.SupplierContactPerson = new List <SupplierContactPerson>(); fuelSupplier.SupplierContactPerson.Add(supplierContactPerson); db.FuelSupplier.Add(fuelSupplier); db.SaveChanges(); var contentAppName = db.ContentManagement.Where(cm => cm.Name == "app_name") .FirstOrDefault(); string AppName = contentAppName == null ? "Fuel Services" : contentAppName.DisplayName; var token = await UserManager.GenerateEmailConfirmationTokenAsync(user); byte[] tokenGeneratedBytes = Encoding.UTF8.GetBytes(token); var code = WebEncoders.Base64UrlEncode(tokenGeneratedBytes); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { userId = user.Id, code = code }, protocol: Request.Scheme); EmailBodyDefaultParams emailBodyDefaultParams = db.EmailBodyDefaultParams .Where(e => e.EmailTypeName == "confirm_mail").FirstOrDefault(); string body = EmailSender.CreateEmailBody(emailBodyDefaultParams); body = body.Replace("{callbackurl}", HtmlEncoder.Default.Encode(callbackUrl)); var simpleResponse = EmailSender.SendEmail(model.Email, AppName, body); //var token = GetTokenForUser(user); return(new JsonResult(new Response <bool>(Constants.SUCCESS_CODE, true, simpleResponse.Message))); } else { string errors = ""; foreach (var error in result.Errors) { errors += error; } Serilog.Log.Error("Register Supplier", model.Email, errors); } } else { return(new JsonResult(new Response <bool>(Constants.INVALID_INPUT_CODE, false, Constants.INVALID_INPUT))); } } catch (Exception e) { Serilog.Log.Error(e, Constants.LogTemplates.LOGIN_ERROR_EX, model.Email); return(new JsonResult(new Response <bool>(Constants.SOMETHING_WRONG_CODE, false, GetExceptionMessage(e)))); } return(new JsonResult(new Response <bool>(Constants.SOMETHING_WRONG_CODE, false, Constants.SOMETHING_WRONG))); }