public IActionResult Seed(SeedingViewModel model) { if (model.WebSetting) { SeedWebSetting(); } return(RedirectToAction("Index")); }
public async Task <ActionResult <Seeding> > AddSeeding([FromBody] SeedingViewModel input) { try { Seeding seeding = null; if (input != null) { seeding = input.Adapt <Seeding>(); var user = _context.Users.Where(s => s.ID == input.UserId).FirstOrDefault(); if (user == null) { return(new JsonResult(new { ErrorMessage = "The given user id not found." })); } seeding.User = user; var PartLandDetails = _context.PartitionLandDetails.Where(p => p.ID == input.PartitionLandDetailId).FirstOrDefault(); if (PartLandDetails == null) { return(new JsonResult(new { ErrorMessage = "The given land details id not found." })); } seeding.PartitionLandDetail = PartLandDetails; //Deciding whether the action is Add or Update if (input.ID <= 0) //Add { _context.Seedings.Add(seeding); } else { //Update _context.Seedings.Update(seeding); } } await _context.SaveChangesAsync(); return(new JsonResult(seeding)); } catch (Exception _ex) { return(new JsonResult(new { ErrorMessage = _ex.Message })); } }