public Response Create(CreateFoodViewModel model) { if (string.IsNullOrWhiteSpace(model.Name)) { return(null); } var file = Request.Files["Photo"]; var url = AzureHelper.Upload(file, "Photo", Guid.NewGuid()); var createdFood = new Food() { Name = model.Name, Carbohidrates = model.Carbohydrates, Description = model.Description, Fats = model.Fats, Fiber = model.Fibre, Proteins = model.Proteins, Sugar = model.Sugar, Grams = model.Grams, Calories = model.Calories, PictureUrl = url, Status = (int)EntityStatus.ACTIVE }; var foodCreationResponse = FoodCore.Create(createdFood); if (foodCreationResponse == null) { return(ResponseFactory.ErrorReponse); } return(ResponseFactory.SuccessResponse); }
public IActionResult GetAll() { try { FoodCore foodCore = new FoodCore(dbContext); return(Ok(foodCore.GetAll())); } catch (Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex)); } }
public IActionResult Update([FromBody] Food food, [FromRoute] int id) { try { FoodCore foodCore = new FoodCore(dbContext); foodCore.Update(food, id); return(Ok("food Word Updated Succesfully")); } catch (Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex)); } }
public IActionResult Create([FromBody] Food food) { try { FoodCore foodCore = new FoodCore(dbContext); foodCore.Create(food); return(Ok("food Added Succesfully")); } catch (Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex)); } }
public IActionResult Delete([FromRoute] int id) { try { FoodCore foodCore = new FoodCore(dbContext); foodCore.Delete(id); return(Ok("recipe Word Deleted Succesfully")); } catch (Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex)); } }
public JsonResult GetFoodDetails(Guid foodId) { if (foodId == Guid.Empty) { return(Json(ResponseFactory.ErrorReponse)); } var foodDetails = FoodCore.GetFoodDetails(foodId); if (foodDetails == null) { return(Json(ResponseFactory.ErrorReponse)); } return(Json(ResponseFactory.Success((int)ResponseCode.Success, foodDetails), JsonRequestBehavior.AllowGet)); }
public async Task <JsonResult> GetFoodItems(string term) { Expression <Func <Food, bool> > expression = t => t.Status == (int)EntityStatus.ACTIVE; if (!string.IsNullOrWhiteSpace(term)) { expression = t => t.Status == (int)EntityStatus.ACTIVE && t.Name.Contains(term.Trim()); } var foods = await FoodCore.GetListAsync(expression).ConfigureAwait(false); if (foods == null) { return(Json(new List <Food>())); } return(Json(foods, JsonRequestBehavior.AllowGet)); }
public JsonResult Delete(Guid foodId) { if (foodId == Guid.Empty) { return(Json(ResponseFactory.ErrorReponse)); } try { FoodCore.Delete(foodId); } catch (Exception ex) { return(Json(ResponseFactory.ErrorReponse)); } return(Json(ResponseFactory.SuccessResponse, JsonRequestBehavior.AllowGet)); }
public JsonResult GetFoodList() { var Foods = FoodCore.GetListEF(t => t.Status == (int)EntityStatus.ACTIVE); var returnedFoods = new List <FoodDropdownItems>(); if (Foods != null && Foods.Count > 0) { foreach (var item in Foods) { returnedFoods.Add(new FoodDropdownItems { Id = item.Id, Name = item.Name, }); } } return(Json(returnedFoods, JsonRequestBehavior.AllowGet)); }
public Response Update(CreateFoodViewModel model) { if (string.IsNullOrWhiteSpace(model.Name)) { return(null); } var foodItem = FoodCore.Get(model.Id); if (foodItem == null) { return(ResponseFactory.ErrorReponse); } if (!string.IsNullOrWhiteSpace(model.Photo) && model.Photo != "undefined") { var file = Request.Files["Photo"]; var url = AzureHelper.Upload(file, "Photo", Guid.NewGuid()); foodItem.PictureUrl = url; } foodItem.Name = model.Name; foodItem.Carbohidrates = model.Carbohydrates; foodItem.Description = model.Description; foodItem.Fats = model.Fats; foodItem.Fiber = model.Fibre; foodItem.Proteins = model.Proteins; foodItem.Sugar = model.Sugar; foodItem.Grams = model.Grams; foodItem.Calories = model.Calories; foodItem.Status = (int)EntityStatus.ACTIVE; var foodCreationResponse = FoodCore.Update(foodItem); if (foodCreationResponse == null) { return(ResponseFactory.ErrorReponse); } return(ResponseFactory.SuccessResponse); }