public JsonResult SaveData(string strDepot) { JavaScriptSerializer serializer = new JavaScriptSerializer(); Depot depot = serializer.Deserialize <Depot>(strDepot); bool status = false; string message = string.Empty; //add new employee if id = 0 if ((depot.Nom == null)) { status = false; } else { if (depot.DepotId == 0) { try { _DepotRepository.Add(depot); status = true; } catch (Exception ex) { status = false; message = ex.Message; } } else { //update existing DB //save db var entity = _DepotRepository.GetById(depot.DepotId); entity.Nom = depot.Nom; entity.Adresse = depot.Adresse; entity.Tel = depot.Tel; entity.DepotId = depot.DepotId; try { _DepotRepository.Update(entity); status = true; } catch (Exception ex) { status = false; message = ex.Message; } } } return(Json(new { status = status, message = message })); }
public IActionResult Create(DepotModel cust) { ViewData["UserNameM"] = HttpContext.Session.GetString("name") + " " + HttpContext.Session.GetString("surname"); ViewData["department"] = HttpContext.Session.GetString("department"); if (ModelState.IsValid) { DepotRepository.Add(cust); return(RedirectToAction("Index")); } return(View(cust)); }