public int UpdateIngredientCategory(IngredientCategoryModel ingredientCategoryModel) { int result = 0; using (SqlConnection con = new SqlConnection(_ConnectionString.Value.ConnectionString)) { CommonRepository commonRepository = new CommonRepository(_ConnectionString); result = commonRepository.GetValidateUnique("IngredientCategory", "IngredientCategoryName", ingredientCategoryModel.IngredientCategoryName, ingredientCategoryModel.Id.ToString()); if (result > 0) { return(-1); } con.Open(); SqlTransaction sqltrans = con.BeginTransaction(); var query = "UPDATE IngredientCategory SET IngredientCategoryName =@IngredientCategoryName," + "RawMaterialId=@RawMaterialId,Notes = @Notes, " + "IsActive = @IsActive " + "WHERE Id = @Id;"; result = con.Execute(query, ingredientCategoryModel, sqltrans, 0, System.Data.CommandType.Text); if (result > 0) { sqltrans.Commit(); string output = commonRepository.SyncTableStatus("IngredientCategory"); } else { sqltrans.Rollback(); } } return(result); }
public IHttpActionResult PostGroceryCategory(IngredientCategoryModel ingredientCategoryModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var ingredientCategory = new IngredientCategory(); ObjectFactory.Parse(ingredientCategoryModel, ingredientCategory); _ingredientCategoryService.Add(ingredientCategory); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = ingredientCategory.Id }, ingredientCategory)); }
private string ValidationIngredientCategory(IngredientCategoryModel ingredientCategoryModel) { string ErrorString = string.Empty; if (string.IsNullOrEmpty(ingredientCategoryModel.IngredientCategoryName)) { ErrorString = _locService.GetLocalizedHtmlString("ValidAddOnesName"); return(ErrorString); } //if (string.IsNullOrEmpty(ingredientCategoryModel.Price.ToString()) || ingredientCategoryModel.Price == 0) //{ // ErrorString = _locService.GetLocalizedHtmlString("ValidPrice"); // return ErrorString; //} return(ErrorString); }
// GET: IngredientCategoryController/Details/5 public ActionResult IngredientCategory(int?id) { IngredientCategoryModel ingredientCategoryModel = new IngredientCategoryModel(); if (UserRolePermissionForPage.Add == true || UserRolePermissionForPage.Edit == true) { if (id > 0) { int ingredientCategroyId = Convert.ToInt32(id); ingredientCategoryModel = _iIngredientCategoryService.GetIngredientCategoryById(ingredientCategroyId); } ingredientCategoryModel.RawMaterialList = _iDropDownService.GetRawMaterialList(); return(View(ingredientCategoryModel)); } else { return(RedirectToAction("NotFound", "Error")); } }
public ActionResult IngredientCategory(IngredientCategoryModel ingredientCategoryModel, string submitButton) { if (!ModelState.IsValid) { string errorString = this.ValidationIngredientCategory(ingredientCategoryModel); if (!string.IsNullOrEmpty(errorString)) { ViewBag.Validate = errorString; return(View(ingredientCategoryModel)); } } if (ingredientCategoryModel.Id > 0) { var result = _iIngredientCategoryService.UpdateIngredientCategory(ingredientCategoryModel); if (result == -1) { ModelState.AddModelError("IngredientCategoryName", "Category already exists"); ingredientCategoryModel.RawMaterialList = _iDropDownService.GetRawMaterialList(); return(View(ingredientCategoryModel)); } ViewBag.Result = _locService.GetLocalizedHtmlString("EditSuccss"); } else { var result = _iIngredientCategoryService.InsertIngredientCategory(ingredientCategoryModel); if (result == -1) { ModelState.AddModelError("IngredientCategoryName", "Category already exists"); ingredientCategoryModel.RawMaterialList = _iDropDownService.GetRawMaterialList(); return(View(ingredientCategoryModel)); } ViewBag.Result = _locService.GetLocalizedHtmlString("SaveSuccess"); } ingredientCategoryModel.RawMaterialList = _iDropDownService.GetRawMaterialList(); return(RedirectToAction("Index", "IngredientCategory")); }
public int InsertIngredientCategory(IngredientCategoryModel ingredientCategoryModel) { int result = 0; using (SqlConnection con = new SqlConnection(_ConnectionString.Value.ConnectionString)) { CommonRepository commonRepository = new CommonRepository(_ConnectionString); result = commonRepository.GetValidateUnique("IngredientCategory", "IngredientCategoryName", ingredientCategoryModel.IngredientCategoryName, ingredientCategoryModel.Id.ToString()); if (result > 0) { return(-1); } int MaxId = commonRepository.GetMaxId("IngredientCategory"); con.Open(); SqlTransaction sqltrans = con.BeginTransaction(); var query = "INSERT INTO IngredientCategory (Id,IngredientCategoryName," + "RawMaterialId,Notes, " + "IsActive)" + "VALUES (" + MaxId + ",@IngredientCategoryName," + "@RawMaterialId,@Notes," + "@IsActive); SELECT CAST(SCOPE_IDENTITY() as INT);"; result = con.Execute(query, ingredientCategoryModel, sqltrans, 0, System.Data.CommandType.Text); if (result > 0) { sqltrans.Commit(); string output = commonRepository.SyncTableStatus("IngredientCategory"); } else { sqltrans.Rollback(); } return(result); } }
public async Task <IHttpActionResult> PutGroceryCategory(int id, IngredientCategoryModel ingredientCategoryModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != ingredientCategoryModel.Id) { return(BadRequest()); } var ingredientCategory = _ingredientCategoryService.GetById(id); ObjectFactory.Parse(ingredientCategoryModel, ingredientCategory); _ingredientCategoryService.Update(ingredientCategory); try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GroceryCategoryExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public int UpdateIngredientCategory(IngredientCategoryModel ingredientCategoryModel) { return(_IIngredientCategoryRepository.UpdateIngredientCategory(ingredientCategoryModel)); }
public int InsertIngredientCategory(IngredientCategoryModel ingredientCategoryModel) { return(_IIngredientCategoryRepository.InsertIngredientCategory(ingredientCategoryModel)); }