public ActionResult ProductionFormula(int?id, int?foodMenuType, string type) { ProductionFormulaModel productionFormulaModel = new ProductionFormulaModel(); TempData["foodMenuType"] = foodMenuType; if (UserRolePermissionForPage.Add == true || UserRolePermissionForPage.Edit == true || UserRolePermissionForPage.View == true) { if (id > 0) { ViewBag.ActionType = type; productionFormulaModel = _iProductionFormulaService.GetProductionFormulaById(Convert.ToInt32(id)); } else { productionFormulaModel.FoodmenuType = (int)foodMenuType; productionFormulaModel.IsActive = true; } productionFormulaModel.FoodMenuList = _iDropDownService.GetFoodMenuListByFoodmenuType((int)foodMenuType); productionFormulaModel.IngredientList = _iDropDownService.GetIngredientList(); productionFormulaModel.BatchSizeUnitsList = _iDropDownService.GetUnitList(); return(View(productionFormulaModel)); } else { return(RedirectToAction("NotFound", "Error")); } }
public ProductionFormulaModel GetProductionFormulaViewById(int id) { ProductionFormulaModel productionFormulaModel = new ProductionFormulaModel(); productionFormulaModel = iProductionFormulaRepository.GetProductionFormulaViewById(id); productionFormulaModel.productionFormulaFoodMenuModels = iProductionFormulaRepository.GetProductionFormulaFoodMenuDetailsView(id); productionFormulaModel.productionFormulaIngredientModels = iProductionFormulaRepository.GetProductionFormulaIngredientDetailsView(id); return(productionFormulaModel); }
public ProductionFormulaModel GetProductionFormulaById(int id) { ProductionFormulaModel productionFormulaModel = new ProductionFormulaModel(); using (SqlConnection con = new SqlConnection(_ConnectionString.Value.ConnectionString)) { var query = "select Id,FormulaName,[BatchSize],[BatchSizeUnitId],FoodmenuType,IsActive from ProductionFormula Where IsDeleted=0 And Id=" + id; productionFormulaModel = con.QueryFirstOrDefault <ProductionFormulaModel>(query); } return(productionFormulaModel); }
public ProductionFormulaModel GetProductionFormulaViewById(int id) { ProductionFormulaModel productionFormulaModel = new ProductionFormulaModel(); using (SqlConnection con = new SqlConnection(_ConnectionString.Value.ConnectionString)) { var query = "select PF.Id,PF.FormulaName,PF.[BatchSize],PF.[BatchSizeUnitId],PF.FoodmenuType,PF.IsActive,U.UnitName from ProductionFormula PF Inner Join Units U On U.Id=PF.BatchSizeUnitId Where PF.IsDeleted=0 And PF.Id=" + id; productionFormulaModel = con.QueryFirstOrDefault <ProductionFormulaModel>(query); } return(productionFormulaModel); }
public ActionResult View(long?id) { ProductionFormulaModel productionFormulaModel = new ProductionFormulaModel(); if (UserRolePermissionForPage.View == true) { productionFormulaModel = _iProductionFormulaService.GetProductionFormulaViewById(Convert.ToInt32(id)); return(View(productionFormulaModel)); } else { return(RedirectToAction("NotFound", "Error")); } }
public ActionResult ProductionFormula(ProductionFormulaModel productionFormulaModel) { int result = 0; string productionFormulaMessage = string.Empty; if (productionFormulaModel != null) { if (productionFormulaModel.productionFormulaFoodMenuModels.Count > 0 && productionFormulaModel.productionFormulaIngredientModels.Count > 0) { if (productionFormulaModel.Id > 0) { result = _iProductionFormulaService.UpdateProductionFormula(productionFormulaModel); if (result > 0) { productionFormulaMessage = _locService.GetLocalizedHtmlString("EditSuccss"); } } else { result = _iProductionFormulaService.InsertProductionFormula(productionFormulaModel); if (result > 0) { productionFormulaMessage = _locService.GetLocalizedHtmlString("SaveSuccess"); } else if (result == -1) { productionFormulaMessage = _locService.GetLocalizedHtmlString("Recipe formula already created for this Menu item "); return(Json(new { error = true, message = productionFormulaMessage, status = 201 })); } } } else { productionFormulaMessage = _locService.GetLocalizedHtmlString("ValidProductionFormula"); return(Json(new { error = true, message = productionFormulaMessage, status = 201 })); } } else { productionFormulaMessage = _locService.GetLocalizedHtmlString("ValidProductionFormula"); return(Json(new { error = true, message = productionFormulaMessage, status = 201 })); } return(Json(new { error = false, message = productionFormulaMessage, status = 200 })); }
public int UpdateProductionFormula(ProductionFormulaModel productionFormulaModel) { return(iProductionFormulaRepository.UpdateProductionFormula(productionFormulaModel)); }
public int InsertProductionFormula(ProductionFormulaModel productionFormulaModel) { return(iProductionFormulaRepository.InsertProductionFormula(productionFormulaModel)); }
public int UpdateProductionFormula(ProductionFormulaModel productionFormulaModel) { int result = 0, deleteFoodMenuResult = 0, deleteIngredientResult = 0, foodmenudetails = 0, ingredientdetails = 0; using (SqlConnection con = new SqlConnection(_ConnectionString.Value.ConnectionString)) { con.Open(); SqlTransaction sqltrans = con.BeginTransaction(); var query = "Update [dbo].[ProductionFormula] set " + " FormulaName = @FormulaName " + ",BatchSize = @BatchSize " + ",BatchSizeUnitId = @BatchSizeUnitId " + ",IsActive = @IsActive " + " ,[UserIdUpdated] = " + LoginInfo.Userid + " " + " ,[DateUpdated] = GetUtcDate() where id= " + productionFormulaModel.Id + ";"; result = con.Execute(query, productionFormulaModel, sqltrans, 0, System.Data.CommandType.Text); if (result > 0) { if (productionFormulaModel.FoodMenuDeletedId != null) { foreach (var item in productionFormulaModel.FoodMenuDeletedId) { var deleteQuery = $"update ProductionFormulaFoodmenu set IsDeleted = 1, UserIdDeleted = " + LoginInfo.Userid + ", DateDeleted = GetutcDate() where id = " + item + ";"; deleteFoodMenuResult = con.Execute(deleteQuery, null, sqltrans, 0, System.Data.CommandType.Text); } } if (productionFormulaModel.IngredientDeletedId != null) { foreach (var item in productionFormulaModel.IngredientDeletedId) { var deleteQuery = $"update ProductionFormulaIngredient set IsDeleted = 1, UserIdDeleted = " + LoginInfo.Userid + ", DateDeleted = GetutcDate() where id = " + item + ";"; deleteIngredientResult = con.Execute(deleteQuery, null, sqltrans, 0, System.Data.CommandType.Text); } } foreach (var item in productionFormulaModel.productionFormulaFoodMenuModels) { var queryDetails = string.Empty; if (item.PFFoodMenuId > 0) { queryDetails = "Update [dbo].[ProductionFormulaFoodmenu] set " + "[FoodMenuId] = "+ item.FoodMenuId + ",[ExpectedOutput] = " + item.ExpectedOutput + " ,[UserIdUpdated] = " + LoginInfo.Userid + "," + " [DateUpdated] = GetUTCDate() " + " where id = " + item.PFFoodMenuId + ";"; } else { queryDetails = "INSERT INTO [dbo].[ProductionFormulaFoodmenu]" + " ([ProductionFormulaId] " + " ,[FoodMenuId] " + " ,[ExpectedOutput] " + " ,[UserIdInserted]" + " ,[DateInserted]" + " ,[IsDeleted]) " + "VALUES " + "(" + productionFormulaModel.Id + "," + item.FoodMenuId + "," + item.ExpectedOutput + "," + LoginInfo.Userid + ",GetUtcDate(),0);"; } foodmenudetails = con.Execute(queryDetails, null, sqltrans, 0, System.Data.CommandType.Text); } foreach (var item in productionFormulaModel.productionFormulaIngredientModels) { var queryDetails = string.Empty; if (item.PFIngredientId > 0) { queryDetails = "Update [dbo].[ProductionFormulaIngredient] set " + "[IngredientId] = "+ item.IngredientId + ",[IngredientQty] = " + item.IngredientQty + " ,[UserIdUpdated] = " + LoginInfo.Userid + "," + " [DateUpdated] = GetUTCDate() " + " where id = " + item.PFIngredientId + ";"; } else { queryDetails = "INSERT INTO [dbo].[ProductionFormulaIngredient]" + " ([ProductionFormulaId] " + " ,[IngredientId] " + " ,[IngredientQty] " + " ,[UserIdInserted]" + " ,[DateInserted]" + " ,[IsDeleted]) " + "VALUES " + "(" + productionFormulaModel.Id + "," + item.IngredientId + "," + item.IngredientQty + "," + LoginInfo.Userid + ",GetUtcDate(),0);"; } ingredientdetails = con.Execute(queryDetails, null, sqltrans, 0, System.Data.CommandType.Text); } if (foodmenudetails > 0 && ingredientdetails > 0) { sqltrans.Commit(); } else { sqltrans.Rollback(); } } else { sqltrans.Rollback(); } } return(result); }
public int InsertProductionFormula(ProductionFormulaModel productionFormulaModel) { int result = 0; if (productionFormulaModel.FoodmenuType == 2) { result = GeProductionFormulaFoodmenuExists(productionFormulaModel.Id, productionFormulaModel.productionFormulaFoodMenuModels[0].FoodMenuId); if (result > 0) { return(-1); } } int foodMenuResult = 0, ingredientResult = 0; using (SqlConnection con = new SqlConnection(_ConnectionString.Value.ConnectionString)) { con.Open(); SqlTransaction sqltrans = con.BeginTransaction(); var query = "INSERT INTO [dbo].[ProductionFormula] " + " ([FormulaName] " + " ,[BatchSize] " + " ,[BatchSizeUnitId] " + " ,[FoodmenuType] " + " ,[IsActive] " + " ,[UserIdInserted] " + " ,[DateInserted] " + " ,[IsDeleted]) " + " VALUES " + " (@FormulaName " + " ,@BatchSize " + " ,@BatchSizeUnitId " + " ,@FoodmenuType " + " ,@IsActive, " + "" + LoginInfo.Userid + "," + " GetUtcDate(), " + " 0); SELECT CAST(SCOPE_IDENTITY() as int); "; result = con.ExecuteScalar <int>(query, productionFormulaModel, sqltrans, 0, System.Data.CommandType.Text); if (result > 0) { foreach (var foodmenu in productionFormulaModel.productionFormulaFoodMenuModels) { var queryDetails = "INSERT INTO [dbo].[ProductionFormulaFoodmenu]" + " ([ProductionFormulaId] " + " ,[FoodMenuId] " + " ,[ExpectedOutput] " + " ,[UserIdInserted]" + " ,[DateInserted]" + " ,[IsDeleted]) " + "VALUES " + "(" + result + "," + foodmenu.FoodMenuId + "," + foodmenu.ExpectedOutput + "," + LoginInfo.Userid + ",GetUtcDate(),0);"; foodMenuResult = con.Execute(queryDetails, null, sqltrans, 0, System.Data.CommandType.Text); } foreach (var ingredient in productionFormulaModel.productionFormulaIngredientModels) { var queryDetails = "INSERT INTO [dbo].[ProductionFormulaIngredient]" + " ([ProductionFormulaId] " + " ,[IngredientId] " + " ,[IngredientQty] " + " ,[UserIdInserted]" + " ,[DateInserted]" + " ,[IsDeleted]) " + "VALUES " + "(" + result + "," + ingredient.IngredientId + "," + ingredient.IngredientQty + "," + LoginInfo.Userid + ",GetUtcDate(),0);"; ingredientResult = con.Execute(queryDetails, null, sqltrans, 0, System.Data.CommandType.Text); } if (foodMenuResult > 0 && ingredientResult > 0) { sqltrans.Commit(); } else { sqltrans.Rollback(); } } else { sqltrans.Rollback(); } } return(result); }