public string Post([FromBody] User value) { //See if User exists if (!dBContext.User.Any(user => user.UserName.Equals(value.UserName))) { User user = new User(); user.UserName = value.UserName; user.Salt = Convert.ToBase64String(Common.GetRandomSalt(16)); user.Password = Convert.ToBase64String(Common.SaltHashPassword(Encoding.ASCII.GetBytes(value.Password), Convert.FromBase64String(user.Salt))); user.Name = value.Name; user.Surename = value.Surename; try { dBContext.Add(user); dBContext.SaveChanges(); return(JsonConvert.SerializeObject("Register successfully")); } catch (Exception ex) { return(JsonConvert.SerializeObject(ex.Message)); } } else { return(JsonConvert.SerializeObject("User is existing in Database")); } }
public void Post([FromBody] Grocery g) { _con.Groceries.Add(g); _con.SaveChanges(); }