public ActionResult ReservationSave(ReservationWrapper wrap) { try { Reservation res = Mapper.Map<ReservationViewModel, Reservation>(wrap.Reservation); List<string> invites = Session[Constants.Invite] as List<string>; List<string> tables = Session[Constants.Table] as List<string>; if(tables == null || tables.Count == 0) { return Json(new { Status = "Sto nije izabran" }, JsonRequestBehavior.AllowGet); } else { invites.ForEach(i => { res.Invites.Add(new Invite() { ReservationId = res.Id, UserId = Convert.ToInt32(i) }); }); tables.ForEach(t => { res.Tables.Add(restaurantService.Get(res.RestaurantId).Tables.First(x => x.Id == Convert.ToInt32(t))); }); reservationService.Create(res); reservationService.Save(); //posalji pozivnice res.Invites.ToList().ForEach(i => { User u = userService.Get(i.UserId); SendMail(u.Email, u.Id , res.Id); }); return Json(new { Status = "Uspesno rezervisano" }, JsonRequestBehavior.AllowGet); } } catch (Exception ex) { return Json(new { Status = ex.InnerException }, JsonRequestBehavior.AllowGet); } }
public ActionResult NewReservation(int restId) { User u = Session[Constants.User] as User; if (u == null) { return RedirectToAction("Login", "Account"); } HashSet<Friend> temp = new HashSet<Friend>(friendService.GetAll().Where(x => (x.User1Id == u.Id || x.User2Id == u.Id))); temp.ToList().ForEach(x => { if (x.User1Id == u.Id) { //ako sam ja user1 ok je } else { //ako sam user 2 , switch, zbog frontenda lakseg x.User2Id = x.User1Id; x.User2 = x.User1; } }); ReservationViewModel rvm = new ReservationViewModel(); rvm.RestaurantId = restId; rvm.Restaurant = restaurantService.Get(restId); rvm.PersonReservedId = u.Id; rvm.PersonReserved = u; rvm.Time = DateTime.Now; ReservationWrapper wrap = new ReservationWrapper() { Reservation = rvm, Friends = temp }; return PartialView("NewReservation", wrap); }