Ejemplo n.º 1
0
		public async Task<ActionResult> List()
		{
			var model = new MealModel();
			var response = await _mealsService.GetMeals();

			return View(model.Adapt(response.Meals));
		}
Ejemplo n.º 2
0
		// GET: Meals/Edit/5
		public async Task<ActionResult> Edit(int id)
		{
			if (id == 0) return new HttpStatusCodeResult(HttpStatusCode.BadRequest);

			var model = new MealModel();
			var getMealResponse = await _mealsService.GetMealById(new GetMealRequest
			{
				MealId = id,
				CorrelationId = Guid.NewGuid().ToString(),
				Requestor = ClaimsPrincipal.Current.Identity.Name
			}).ConfigureAwait(false);

			if (getMealResponse.Meal == null) return HttpNotFound();

			return View(model.Adapt(getMealResponse.Meal));
		}
Ejemplo n.º 3
0
		public async Task<ActionResult> Create(MealModel meal)
		{
			if (ModelState.IsValid)
			{
				await _mealsService.CreateMeal(new CreateMealRequest
				{
					Name = meal.Name,
					Description = meal.Description,
					Category = (int)meal.Category,
					Price = meal.Price,
					CorrelationId = Guid.NewGuid().ToString(),
					Requestor = ClaimsPrincipal.Current.Identity.Name
				}).ConfigureAwait(false);
				return RedirectToAction("List");
			}

			return View(meal);
		}
Ejemplo n.º 4
0
		public async Task<ActionResult> DeleteConfirmed(int id)
		{
			var model = new MealModel();
			var getMealResponse = await _mealsService.GetMealById(new GetMealRequest
			{
				MealId = id,
				CorrelationId = Guid.NewGuid().ToString(),
				Requestor = ClaimsPrincipal.Current.Identity.Name
			});
			if (getMealResponse.Meal.Menus.Any())
			{
				model = model.Adapt(getMealResponse.Meal);
				model.ErrorsOccured = true;
				model.ErrorMessage = "There are menus associated with this company.";
				return View(model);
			}
			await _mealsService.DeleteMeal(new DeleteMealRequest
			{
				MealId = id,
				CorrelationId = Guid.NewGuid().ToString(),
				Requestor = ClaimsPrincipal.Current.Identity.Name
			}).ConfigureAwait(false);
			return RedirectToAction("List");
		}