public async Task <IActionResult> PutRoles(long id, Roles roles) { if (id != roles.Id) { return(BadRequest()); } _context.Entry(roles).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RolesExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutCategories(long id, Categories model) { var categoryId = model.CategoryName; var categories = _context.Categories.FirstOrDefault(m => m.Id == id); if (model != null) { categories.CategoryName = model.CategoryName; _context.Update(categories); await _context.SaveChangesAsync(); return(Ok()); } return(BadRequest()); }
public async Task <ActionResult <User> > Create(User model) { RandomGenerate random = new RandomGenerate(); string str = RandomGenerate.CreateRandomPasswordWithRandomLength(); var firstName = model.FirstName; var lastName = model.LastName; var userName = model.UserName; var role = model.Role; var token = model.Token; var email = model.Email; var salt = SaltGenerator.SaltMethod(); var password = _hashingService.ComputeSha256Hash(str, salt); var user = _context.User.Where(x => x.FirstName == model.FirstName).ToList(); if (user.Any() || !user.Any()) { var users = new User() { FirstName = firstName, LastName = lastName, UserName = userName, Password = password, Role = role, Email = email, Salt = salt }; _context.User.Add(users); await _context.SaveChangesAsync(); //var callback = Url.Page("/localhost:3000" // , pageHandler: null, // values: new { UserId = model.UserName }, // protocol: Request.Scheme // ); var callback = "http://localhost:3000/users/changepassword/" + users.Id; //ussername === email await _emailSender.SendEmailAsync(model.Email, "Change Your Password", $"<p>hi {model.UserName}, your username & password is: <br> Username: {model.UserName} Password:{str}</p><br><p>Please change your password by <a href='{HtmlEncoder.Default.Encode(callback)}'>clicking here</a></p>."); return(Ok()); } return(BadRequest()); }
public async Task <ActionResult <BusinessListing> > PutTodoItem(long id, BusinessListing model) { // var id = model.Id; var customerName = model.CustomerName; var emailAddress = model.Email; var businessName = model.BusinessName; var businessAddress = model.Address; var city = model.City; var lga = model.Lga; var url = model.Url; var businessDescription = model.Description; var categoryId = model.CategoryId; var categories = _context.Categories.Where(m => m.Id == categoryId); var businesslisting = _context.BusinessListing.FirstOrDefault(m => m.Id == id); if (model != null) { businesslisting.CustomerName = model.CustomerName; businesslisting.Email = model.Email; businesslisting.BusinessName = model.BusinessName; businesslisting.Address = model.Address; businesslisting.City = model.City; businesslisting.Lga = model.Lga; businesslisting.Url = model.Url; businesslisting.Description = model.Description; _context.Update(businesslisting); await _context.SaveChangesAsync(); } /* if (id != model.Id) * { * return BadRequest(); * }*/ // _context.Entry(model).State = EntityState.Modified; return(Ok()); }