public async Task <IActionResult> CreateFood([FromBody] Models.CreateFoodRequest foodRequest) { try { Entities.Food food = _mapper.Map <Entities.Food>(foodRequest); food.FarmId = int.Parse(User.Claims.First(c => c.Type == "premisesID").Value); var createById = int.Parse(User.Claims.First(c => c.Type == "userID").Value); food.CreateById = createById; await _foodBL.CreateProductAsync(food); var transactionHash = await _foodDataBL.CreateFood(food, food.FarmId, createById); await _foodBL.AddDetail(food.FoodId, EFoodDetailType.CREATE, transactionHash, food.CreateById); return(Ok(new { message = MessageConstant.INSERT_SUCCESS })); } catch (InvalidDataException ex) { return(BadRequest(new { message = ex.Message, error = ex.StackTrace })); } catch (Exception ex) { return(BadRequest(new { message = MessageConstant.UNHANDLE_ERROR, error = ex.StackTrace })); } }
public async Task <IActionResult> AddTreatment(int foodId, [FromBody] string treatmentId) { try { var providerId = int.Parse(User.Claims.First(c => c.Type == "premisesID").Value); var userId = int.Parse(User.Claims.First(c => c.Type == "userID").Value); var transactionHash = await _foodDataBL.AddTreatment(foodId, int.Parse(treatmentId), providerId, userId); await _foodBL.AddDetail(foodId, EFoodDetailType.TREATMENT, transactionHash, userId); Entities.ProviderFood food = await _foodBL.getFoodById(foodId, providerId); await _foodBL.UpdateFoodTreatment(food, foodId, int.Parse(treatmentId), providerId); return(Ok(new { message = MessageConstant.INSERT_SUCCESS })); } catch (Exception ex) { return(BadRequest(new { message = MessageConstant.UNHANDLE_ERROR, error = ex.StackTrace })); } }
public async Task <IActionResult> CreateDistributorFood(int id, [FromBody] Models.CreateDistributorFoodRequest foodRequest) { try { Entities.DistributorFood distributorFood = new Entities.DistributorFood(); distributorFood.FoodId = foodRequest.FoodId; distributorFood.PremisesId = id; var createById = 139; var transactionHash = await _foodDataBL.AddDistributor(distributorFood.FoodId, id, createById); await _foodBL.AddDetail(foodRequest.FoodId, EFoodDetailType.DISTRIBUTOR, transactionHash, createById); await _foodBL.createDistributorFood(distributorFood); return(Ok(new { message = MessageConstant.INSERT_SUCCESS })); } catch (Exception e) { return(BadRequest(new { msg = e.Message })); } }