public ActionResult NewManager() { User u = Session[Constants.User] as User; if (u == null) { return RedirectToAction("Login", "Account"); } RestaurantWrapper wrap = new RestaurantWrapper() { Employee = new UserViewModel() }; return PartialView("NewManager", wrap); }
public ActionResult SaveManager(RestaurantWrapper wrap) { User u = Session[Constants.User] as User; if (u == null) { return RedirectToAction("Login", "Account"); } HashSet<User> employees = Session[Constants.Employee] as HashSet<User>; if (employees == null) { employees = new HashSet<Model.Model.User>(); } User emp = Mapper.Map<UserViewModel, User>(wrap.Employee); //nesto ne radi, mrzi me sad emp.RoleId = 3;//roleService.GetByName("menadzer").Id; employees.Add(emp); Session.Add(Constants.Employee, employees); return PartialView("RestaurantEmployees", new RestaurantWrapper() { Employees = Mapper.Map<IEnumerable<User>, IEnumerable<UserViewModel>>(employees) }); }
public ActionResult SaveFood(RestaurantWrapper wrap) { User u = Session[Constants.User] as User; if (u == null) { return RedirectToAction("Login", "Account"); } HashSet<Food> food = Session[Constants.Food] as HashSet<Food>; Food f = Mapper.Map<FoodViewModel, Food>(wrap.Food); if (f.Id == 0) f.Id = -(food.Count - 1); food.Add(f); Session.Add(Constants.Food, food); wrap.Restaurant = new RestaurantViewModel() { Menu = food }; return PartialView("RestaurantFood", wrap); }
public ActionResult DeleteFood(int Id) { User u = Session[Constants.User] as User; if (u == null) { return RedirectToAction("Login", "Account"); } Food ff = foodService.Get(Id); if (ff != null) { foodService.Delete(ff); foodService.Save(); } HashSet<Food> food = Session[Constants.Food] as HashSet<Food>; food.RemoveWhere(f => f.Id == Id); Session.Add(Constants.Food, food); RestaurantWrapper wrap = new RestaurantWrapper() { Restaurant = new RestaurantViewModel() { Menu = food } }; return PartialView("RestaurantFood", wrap); }
public ActionResult Index() { User u = Session[Constants.User] as User; if (u == null) { return RedirectToAction("Login", "Account"); } IEnumerable<Restaurant> restaurants = restaurantService.GetAll(); RestaurantWrapper wrap = new RestaurantWrapper(); IEnumerable<RestaurantViewModel> restaurantsVM = Mapper.Map<IEnumerable<Restaurant>, IEnumerable<RestaurantViewModel>>(restaurants); restaurantsVM.ToList().ForEach(res => { res.PicutreBase64 = "data:image/png;base64," + Convert.ToBase64String(res.Picture, 0, res.Picture.Length); }); HashSet<RestaurantViewModel> temp = new HashSet<RestaurantViewModel>(); //prijatelji zbog ocena HashSet<Friend> frs = new HashSet<Friend>(friendService.GetAll().Where(x => (x.User1Id == u.Id || x.User2Id == u.Id))); frs.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; } }); //OCENEEEEEEEEEEEEEE restaurantsVM.ToList().ForEach(r => { double mark = 0; double markCount = 0; int frMark = 0; int frMarkCount = 0; r.Reservations.ToList().ForEach(rez => { //ukupna if (rez.Mark.HasValue) { mark += rez.Mark.Value; markCount++; } //rez.Invites.ToList().ForEach(i => { // if (i.Mark.HasValue && i.Going == true) // { // mark += i.Mark.Value; // markCount++; // } //}); //prijatelji frs.ToList().ForEach(f => { User f1 = f.User2; f1.Reservations.Where(rz => rz.RestaurantId == r.Id).ToList().ForEach(x => { if (x.Mark.HasValue) { frMark += x.Mark.Value; frMarkCount++; } }); //f1.Events.Where(ev => ev.Reservation.RestaurantId == r.Id && ev.Going == true).ToList().ForEach(x => //{ // if (x.Mark.HasValue) // { // frMark += x.Mark.Value; // frMark++; // } //}); }); }); r.Mark = 0; r.FriendsMark = 0; if(markCount>0) r.Mark = mark / markCount; if(frMarkCount>0) r.FriendsMark = frMark / frMarkCount; temp.Add(r); }); wrap.Restaurants = temp; //manager if (u.Role.Naziv == "menadzer") { wrap.Restaurants = wrap.Restaurants.Where(x => x.Id == u.EmployedId); } wrap.Role = u.Role.Naziv; return View("Index", wrap); }
public ActionResult NewFood() { User u = Session[Constants.User] as User; if (u == null) { return RedirectToAction("Login", "Account"); } RestaurantWrapper wrap = new RestaurantWrapper(); wrap.Food = new FoodViewModel(); return PartialView("NewFood", wrap); }
public ActionResult RestaurantTableSave(RestaurantWrapper wrap) { User u = Session[Constants.User] as User; if (u == null) { return RedirectToAction("Login", "Account"); } HashSet<RestaurantTable> tables = Session[Constants.Table] as HashSet<RestaurantTable>; if (tables == null) tables = new HashSet<RestaurantTable>(); RestaurantTable table = Mapper.Map<RestaurantTableViewModel, RestaurantTable>(wrap.Table); int status = 0; tables.ToList().ForEach(x => { if (x.OrdinalNumber == table.OrdinalNumber && (x.PosX != table.PosX || x.PosY != table.PosY)) status = 1; }); if (status == 0) { tables.RemoveWhere(x => x.OrdinalNumber == table.OrdinalNumber); tables.Add(table); Session.Add(Constants.Table, tables); } return Json(new { Rbr = table.OrdinalNumber, PosX = table.PosX, PosY = table.PosY, Status = status }); }
public ActionResult EditRestaurantTable(string pos) { User u = Session[Constants.User] as User; if (u == null) { return RedirectToAction("Login", "Account"); } HashSet<RestaurantTable> tables = Session[Constants.Table] as HashSet<RestaurantTable>; RestaurantWrapper wrap = new RestaurantWrapper(); wrap.Table = Mapper.Map<RestaurantTable, RestaurantTableViewModel>(tables.First(t => t.OrdinalNumber.Equals(Convert.ToInt32(pos)))); return PartialView("NewRestaurantTable", wrap); }
public ActionResult NewRestaurantTable(string pos) { User u = Session[Constants.User] as User; if (u == null) { return RedirectToAction("Login", "Account"); } RestaurantWrapper wrap = new RestaurantWrapper(); wrap.Table = new RestaurantTableViewModel(); wrap.Table.PosX = Convert.ToInt32(pos.Split('_')[1].Split('-')[0]); wrap.Table.PosY = Convert.ToInt32(pos.Split('_')[1].Split('-')[1]); return PartialView("NewRestaurantTable", wrap); }
public ActionResult EditRestaurant(int Id) { User u = Session[Constants.User] as User; if (u == null) { return RedirectToAction("Login", "Account"); } Restaurant r = restaurantService.Get(Id); RestaurantWrapper wrap = new RestaurantWrapper(); wrap.Restaurant = Mapper.Map<Restaurant, RestaurantViewModel>(r); wrap.Employees = Mapper.Map<IEnumerable<User>, IEnumerable<UserViewModel>>(r.Employees); Session.Add(Constants.File, r.Picture); Session.Add(Constants.Food, r.Menu); Session.Add(Constants.Employee, r.Employees); Session.Add(Constants.Table, new HashSet<RestaurantTable>()); Session.Add(Constants.Food, new HashSet<Food>()); if (r.Picture != null) wrap.Restaurant.PicutreBase64 = "data:image/png;base64," + Convert.ToBase64String(r.Picture, 0, r.Picture.Length); RestaurantFill(); wrap.Role = ((User)Session[Constants.User]).Role.Naziv; return PartialView("NewRestaurant", wrap); }
public ActionResult TypeOfRestaurantSave(RestaurantWrapper wrap) { User u = Session[Constants.User] as User; if (u == null) { return RedirectToAction("Login", "Account"); } //novi tip se upisuje kad i restoran, za sad se cuva u sesiji //Session.Add(Constants.TypeOfRestaurant, wrap.Type); TypeOfRestaurant type = Mapper.Map<TypeOfRestaurantViewModel, TypeOfRestaurant>(wrap.Type); typeOfRestaurantService.Create(type); typeOfRestaurantService.Save(); return Json(new { Id = type.Id, Name = type.Name }); }
public ActionResult RestaurantSave(RestaurantWrapper wrap) { User u = Session[Constants.User] as User; if (u == null) { return RedirectToAction("Login", "Account"); } if (ModelState.IsValid) { Restaurant rest; RestaurantViewModel r = wrap.Restaurant; if (r.Id == 0) { rest = Mapper.Map<RestaurantViewModel, Restaurant>(r); rest.Picture = Session[Constants.File] as Byte[]; //rest.Tables = Session[Constants.Table] as HashSet<RestaurantTable>; //rest.Menu = Session[Constants.Food] as HashSet<Food>; //Session.Remove(Constants.File); //Session.Remove(Constants.Table); //Session.Remove(Constants.Food); //restaurantService.Create(rest); //novo [admin] ne menja hranu i stolove HashSet<User> emp = Session[Constants.Employee] as HashSet<User>; emp.ToList().ForEach(e => e.EmployedId = rest.Id); rest.Employees = emp; Session.Remove(Constants.Employee); restaurantService.Create(rest); restaurantService.Save(); } else { if (u.Role.Naziv == "admin") { rest = Mapper.Map<RestaurantViewModel, Restaurant>(r); rest.Picture = Session[Constants.File] as Byte[]; restaurantService.Update(rest); restaurantService.Save(); HashSet<User> before = new HashSet<User>(restaurantService.Get(r.Id).Employees); HashSet<User> after = Session[Constants.Employee] as HashSet<User>; before.ToList().ForEach(emp => { if (!after.Contains(emp)) { userService.Delete(emp.Id); } }); after.ToList().ForEach(emp => { if (!before.Contains(emp)) { emp.EmployedId = rest.Id; emp.Employed = null; userService.Create(emp); } }); userService.Save(); } //ako je menadzer else { HashSet<RestaurantTable> tables = Session[Constants.Table] as HashSet<RestaurantTable>; tables.ToList().ForEach(t => { t.RestaurantId = wrap.Restaurant.Id; restaurantTableService.Create(t); }); restaurantTableService.Save(); HashSet<Food> before = new HashSet<Food>(restaurantService.Get(wrap.Restaurant.Id).Menu); HashSet<Food> after = Session[Constants.Food] as HashSet<Food>; before.ToList().ForEach(f => { if (!after.Contains(f)) { foodService.Delete(f.Id); } }); after.ToList().ForEach(f => { if (!before.Contains(f)) { f.RestaurantId = wrap.Restaurant.Id; foodService.Create(f); } }); foodService.Save(); Session.Remove(Constants.Table); Session.Remove(Constants.Food); } } return null; } else { Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; return PartialView("_ValidationErrors", ModelState); } }
public ActionResult NewRestaurant() { User u = Session[Constants.User] as User; if (u == null) { return RedirectToAction("Login", "Account"); } RestaurantFill(); RestaurantWrapper wrap = new RestaurantWrapper(); wrap.Restaurant = new RestaurantViewModel(); wrap.Restaurant.Menu = new HashSet<Food>(); wrap.Employees = new HashSet<UserViewModel>(); Session.Remove(Constants.TypeOfRestaurant); Session.Remove(Constants.Table); Session.Remove(Constants.Food); Session.Remove(Constants.Employee); Session.Add(Constants.Food, new HashSet<Food>()); wrap.Role = u.Role.Naziv; return PartialView("NewRestaurant", wrap); }