public Save DeleteSetting(SettingsExt setting) { using (var client = new LLCContext()) { Console.WriteLine(JsonConvert.SerializeObject(setting)); client.Settings.Remove(new Settings { Id = setting.Id }); try { client.SaveChanges(); return(new Save { Status = true }); } catch (Exception e) { Console.WriteLine(e.Message); return(new Save { Status = false }); } } }
public Save SaveSetting(SettingsExt setting, User user) { Console.WriteLine($"ID is {setting.Id}"); Console.WriteLine($"ID is null ? {string.IsNullOrEmpty(setting.Id)}"); var now = DateTime.Now; using (var client = new LLCContext()) { if (string.IsNullOrEmpty(setting.Id)) { Console.WriteLine("Adding setting"); var id = Guid.NewGuid().ToString(); client.Settings.Add(new Settings { DateCreated = now, DateModified = now, Description = setting.Description, Id = id, ModifiedUser = user.Email, Name = setting.Name, Value = setting.Value }); } else { Console.WriteLine("Update setting"); client.Settings.Update(new Settings { DateModified = now, Description = setting.Description, Id = setting.Id, ModifiedUser = user.Email, Name = setting.Name, Value = setting.Value }); } try { client.SaveChanges(); return(new Save { Status = true }); } catch (Exception e) { Console.WriteLine(e.Message); return(new Save { Status = false }); } } }
public JsonResult Post([FromBody] SettingsExt setting) { if (setting.Delete && !string.IsNullOrEmpty(setting.Id)) { return(Json(_service.DeleteSetting(setting))); } else if (ModelState.IsValid) { var user = new User(HttpContext.User.Claims); return(Json(_service.SaveSetting(setting, user))); } return(Json(new Save { Status = false })); }