/// <summary> /// Post example /// </summary> /// <param name="eatingData"></param> public IHttpActionResult Post(EatingData eatingData) { if (!ModelState.IsValid) { return(BadRequest("Input data format is invalid.")); } if (eatingData.Eatings.Count == 0) { return(BadRequest("Eating list can't be empty.")); } ApplicationDbContext context = Request.GetOwinContext().Get <ApplicationDbContext>(); EatingService eatingService = new EatingService(context); UserService userService = new UserService(context); ApplicationUserManager manager = new ApplicationUserManager( new UserStore <ApplicationUser>(context)); ApplicationUser userCredential = manager.FindByName(RequestContext.Principal.Identity.Name); int userId = userService.GetUserIdByUserCredential(userCredential.Id); foreach (var eating in eatingData.Eatings) { eating.IdUser = userId; foreach (var dishEating in eating.DishEating) { dishEating.IdEatinng = 0; } eatingService.Add(eating); } return(Ok()); }
public EatingData Get() { ApplicationDbContext context = Request.GetOwinContext().Get <ApplicationDbContext>(); EatingService eatingService = new EatingService(context); UserService userService = new UserService(context); ApplicationUserManager manager = new ApplicationUserManager( new UserStore <ApplicationUser>(context)); ApplicationUser userCredential = manager.FindByName(RequestContext.Principal.Identity.Name); int userId = userService.GetUserIdByUserCredential(userCredential.Id); return(new EatingData() { Eatings = new List <Eating>() { new Eating() { AmountOfWater = null, Carbs = 1, DishEating = new List <DishEating> { new DishEating { IdDish = 1, IdEatinng = 1 } }, IdUser = 1 } } }); }
public ActionResult Edit([Bind(Include = "Id,IdUser,Date,Proteins,Fat,Carbs,Ccal,Sugar,AmountOfWater")] Eating eating) { if (ModelState.IsValid) { EatingService.Update(eating.Id, eating); return(RedirectToAction("Index")); } ViewBag.IdUser = GetUserSelectList(eating.IdUser); return(View(eating)); }
public ActionResult Search(string name) { var model = EatingService.Get() .Where(e => e.User.FirstName.Contains(name) || e.User.LastName.Contains(name) || e.User.UserCredential.UserName.Contains(name) || e.Id.ToString() == name) .OrderByDescending(e => e.Date).ToList(); return(View("Index", model)); }
// GET: Eatings/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Eating eating = EatingService.Get(id.Value); if (eating == null) { return(HttpNotFound()); } return(View(eating)); }
// GET: Eatings/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Eating eating = EatingService.Get(id.Value); if (eating == null) { return(HttpNotFound()); } ViewBag.IdUser = GetUserSelectList(eating.IdUser); return(View(eating)); }
// GET: Eatings public ActionResult Index() { var eating = EatingService.Get().Include(e => e.User).ToList(); return(View(eating.ToList())); }
public ActionResult DeleteConfirmed(int id) { EatingService.Remove(id); return(RedirectToAction("Index")); }