public ActionResult RegisterMigration(RegisterProductIngridientModel model) { var result = new Dictionary<string, object> { ["isSuccess"] = false, ["error"] = "Something was wrong. Migration has not been added to the database" }; if (!this.ModelState.IsValid) return this.Json(result, JsonRequestBehavior.DenyGet); var helper = new HelperRepository(); var insertedCustomerId = helper.InsertOrUpdateProductIngridient( model.ProductId, model.IngridientId, model.Weight); if (!insertedCustomerId) return this.Json(result, JsonRequestBehavior.DenyGet); result["success"] = $"Migration between {helper.GetProduct(model.ProductId).Name} and {helper.GetIngridient(model.IngridientId).Name} has successfully added to the database"; result["model"] = HelperConverter.GetProductIngridientRowJsonString(model.ProductId, model.IngridientId); result["isSuccess"] = true; return this.Json(result, JsonRequestBehavior.DenyGet); }
public static string GetIngridientRowJsonString(int ingridientId) { var helper = new HelperRepository(); var ingridient = helper.GetIngridient(ingridientId); var result = new Dictionary<string, object> { ["name"] = ingridient.Name, ["description"] = ingridient.Description ?? string.Empty, ["id"] = ingridient.Id }; return new JavaScriptSerializer().Serialize(result); }