public JsonResult UpdateManager(int hotelID, int managerID, int priority, List <HotelUpdateRightsViewModel> rights) { try { var hotel = hotelRepository.GetById(hotelID); var manager = hotelManagerRepository.Get(hotelID, managerID); var hotelRights = new HotelRights() { Priority = priority }; foreach (var right in Enums.ToArray <HotelRightsEnum>()) { hotelRights[right] = rights.First(r => r.HotelRights == right).Value; } var result = hotelService.CanUpdateManager(manager, SessionHelper.CurrentEntity, hotelRights); if (result.IsError) { return(JsonError(result)); } hotelService.UpdateManager(manager, hotelRights); return(JsonSuccess("Manager has been updated!")); } catch (Exception e) { return(JsonDebugOnlyError(e)); } }
public HotelManagerViewModel(int hotelID, HotelManagerModel manager, HotelRights rights, string title = "Manager") { HotelID = hotelID; CitizenID = manager.ManagerID; Avatar = new SmallEntityAvatarViewModel(manager.ManagerID, manager.ManagerName, manager.ImgURL); Rights = manager.HotelRights; ReadOnly = rights.CanManageManagers == false || rights.Priority <= manager.HotelRights.Priority; Title = title; }
public HotelMakeDeliveryViewModel(HotelInfo info, Hotel hotel, HotelRights rights, IQueryable <MarketOfferModel> offers, PagingParam pp, int quality, int productID) { Info = new HotelInfoViewModel(info); WalletIDs.Add(SessionHelper.CurrentEntity.WalletID, "Your wallet"); if (rights.CanUseWallet) { WalletIDs.Add(hotel.Entity.WalletID, "Hotel's wallet"); } Market = new CountryMarketOffersListViewModel(hotel.Entity, hotel.Region.Country, offers.ToList(), Persistent.Countries.GetAll().ToList(), new List <int>() { (int)ProductTypeEnum.Fuel, (int)ProductTypeEnum.ConstructionMaterials }, pp, quality, productID); }
public virtual MethodResult CanUpdateManager(HotelManager manager, Entity currentEntity, HotelRights newRights) { var hotel = manager.Hotel; var oldRights = new HotelRights(manager); var result = CanManageManager(hotel, currentEntity, oldRights); if (result.IsError) { return(result); } var currentRights = GetHotelRigths(hotel, currentEntity); if (newRights.Priority >= currentRights.Priority) { return(new MethodResult("You cannot set priority equal or higher to your actual priority!")); } return(MethodResult.Success); }
public virtual void UpdateManager(HotelManager manager, HotelRights newRights) { newRights.Update(manager); hotelManagerRepository.SaveChanges(); }
public virtual MethodResult CanManageManager(Hotel hotel, Entity currentEntity, HotelRights managerRights) { if (hotel == null) { return(new MethodResult("Hotel does not exist!")); } var rights = GetHotelRigths(hotel, currentEntity); if (rights.CanManageManagers == false) { return(new MethodResult("You cannot manage managers here!")); } if (managerRights.Priority >= rights.Priority) { return(new MethodResult("You cannot manage manager with same or higher priority than you!")); } return(MethodResult.Success); }