public User Create(User user, string password) { if (string.IsNullOrWhiteSpace(password)) { throw new Exception("Password is required"); } if (context.Users.Any(x => x.Login.Equals(user.Login))) { throw new Exception($"Login {user.Login} is already taken"); } CreatePasswordHash(password, out byte[] passwordHash, out byte[] passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; context.Users.Add(user); context.SaveChanges(); return(user); }
public ActionResult Insert(string values) { var filePath = Session["currentFilePath"].ToString(); Session["currentFilePath"] = ""; var newProductGroup = new ProductGroups(); // Create a new item JsonConvert.PopulateObject(values, newProductGroup); // Populate the item with the values newProductGroup.Photo = filePath; if (!TryValidateModel(newProductGroup)) // Validate the item { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Error")); } db.productGroups.Add(newProductGroup); // Add the item to the database db.SaveChanges(); newProductGroup.QRCode = QRGenerator.Generate(Url.Action("ProductList", "ProductGroups", new { id = newProductGroup.Id.ToString() }, Request.Url.Scheme), Server.MapPath("~/Content/Files/"), newProductGroup.Id.ToString()); db.SaveChanges(); return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
public static Result AddMessage(Message message) { try { using (var dbContext = new BasicContext(ConnectionString)) { dbContext.Messages.Add(message); dbContext.SaveChanges(); } return(new Result() { Status = true }); } catch (Exception e) { return(new Result() { Status = false, OutputMessage = e.Message }); } }
/// <summary> /// Save changes /// </summary> /// <param name="ctx"></param> private void SaveChanges(BasicContext ctx) { ctx.SaveChanges(); }
public void AddOrganization(Organizations organization) { db.Organizations.Add(organization); db.SaveChanges(); }