public JsonResult Update(PredefinedMinerClientViewModel model) { if (!ModelState.IsValid) { return(Json(new { Result = "ERROR", Message = BaseResource.Get("InvalidData") })); } try { var dbObj = db.PredefinedMinerClients.FirstOrDefault(ln => ln.Id == model.Id); if (dbObj == null) { return(Json(new { Result = "ERROR", Message = BaseResource.Get("InvalidPredefMinerClientId") })); } if (db.PredefinedMinerClients.Any(ln => ln.ClientId == model.ClientId)) { return(Json(new { Result = "ERROR", Message = BaseResource.Get("PredefClientAlreadyExists") })); } dbObj.ClientId = model.ClientId; dbObj.ScriptUrl = model.ScriptUrl; db.SaveChanges(); return(Json(new { Result = "OK", Message = "data saved.." })); } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); } }
public JsonResult Create(PredefinedMinerClientViewModel model) { if (!ModelState.IsValid) { return(Json(new { Result = "ERROR", Message = BaseResource.Get("InvalidData") })); } if (string.IsNullOrWhiteSpace(model.ScriptUrl) || string.IsNullOrWhiteSpace(model.ClientId)) { return(Json(new { Result = "ERROR", Message = BaseResource.Get("InvalidData") })); } try { if (db.PredefinedMinerClients.Any(ln => ln.Id == model.Id)) { return(Json(new { Result = "ERROR", Message = BaseResource.Get("PredefClientAlreadyExists") })); } var dbobj = db.PredefinedMinerClients.Add(new Models.PredefinedMinerClientModel() { ClientId = model.ClientId, ScriptUrl = model.ScriptUrl }); db.SaveChanges(); return(Json(new { Result = "OK", Record = dbobj.ToPreDefinedMinerClientViewModel() }, JsonRequestBehavior.AllowGet)); } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { string msg = ""; foreach (var ve in ex.EntityValidationErrors) { msg += ve.ValidationErrors.FirstOrDefault().ErrorMessage; } return(Json(new { Result = "ERROR", Message = msg }, JsonRequestBehavior.AllowGet)); } }