public IHttpActionResult ChangeApartment(ApartmentBM apartment) { Apartman app = context.Apartmans.Where(x => x.ID == apartment.ID && x.Deleted == false).FirstOrDefault(); if (app == null) { return(NotFound()); } if (CheckRole("Admin")) { if (CheckRole("Host")) { return(StatusCode(HttpStatusCode.Unauthorized)); } else { apartment.Status = app.Status.ToString(); } } SetApartment(app, apartment); return(Ok()); }
public IHttpActionResult AddApartment(ApartmentBM apartmentBM) { if (CheckRole("Host")) { return(StatusCode(HttpStatusCode.Unauthorized)); } // apartmentBM.HostID = 3; //ovo menjas kad uradis logovanje GetApartmentFromBM(apartmentBM); return(Ok(apartmentBM.ID)); }
public IHttpActionResult GetSearchHostApartments(SearchApartment apartmentDetails) { ICollection <Apartman> apartments = GetFiltredHostApartments(apartmentDetails); List <ApartmentBM> apartmentsInfo = new List <ApartmentBM>(); foreach (var apartment in apartments) { ApartmentBM apartmentBM = GetApartmentInfo(apartment); apartmentsInfo.Add(apartmentBM); } return(Ok(apartmentsInfo)); }
private bool SetApartment(Apartman apartman, ApartmentBM apartmentBM) //change apartmant { apartman.Type = (apartmentBM.Type == ApartmanType.FullApartman.ToString()) ? ApartmanType.FullApartman : ApartmanType.Room; apartman.Status = (apartmentBM.Status == ApartmanStatus.Active.ToString()) ? ApartmanStatus.Active : ApartmanStatus.NotActive; apartman.SingUpTime = apartmentBM.SingUpTime; apartman.SingOutTime = apartmentBM.SingOutTime; apartman.RoomNumber = apartmentBM.RoomNumber; // apartman.RentDates = apartmentBM.RentDates; apartman.PricePerNight = apartmentBM.PricePerNight; ////pic //apartman.Pictures = ""; //foreach (string pic in apartmentBM.Pictures) //{ // apartman.Pictures = pic + ';'; //} apartman.GuestNumber = apartmentBM.GuestNumber; context.SaveChanges(); //location info: Location locationInfo = context.Locations.Where(x => x.ID == apartman.LocationID).FirstOrDefault(); locationInfo.Latitude = apartmentBM.Latitude; locationInfo.Longitude = apartmentBM.Longitude; context.SaveChanges(); //Adress locationInfo.Adress.Streat = apartmentBM.Streat; locationInfo.Adress.StreatNumber = apartmentBM.StreatNumber; locationInfo.Adress.ZipCode = apartmentBM.ZipCode; locationInfo.Adress.Settlement = apartmentBM.Settlement; context.SaveChanges(); //Amenities apartman.Amenities.Clear(); //brise sve postojece foreach (string amm in apartmentBM.Amenities) { Amenitie amenitie = context.Amenities.Where(x => x.Name == amm).FirstOrDefault(); apartman.Amenities.Add(amenitie); } context.SaveChanges(); return(true); }
public IHttpActionResult GetActiveApartments() { List <ApartmentBM> apartmentsInfo = new List <ApartmentBM>(); ICollection <Apartman> apartments = context.Apartmans.Where(x => x.Deleted == false).ToList(); foreach (var apartment in apartments) { if (apartment.Status == Helper.Enums.ApartmanStatus.Active) { ApartmentBM apartmentBM = GetApartmentInfo(apartment); apartmentsInfo.Add(apartmentBM); } } return(Ok(apartmentsInfo)); }
public IHttpActionResult GetHostApartments(int hostId) { if (CheckRole("Host")) { return(StatusCode(HttpStatusCode.Unauthorized)); } List <ApartmentBM> apartmentsInfo = new List <ApartmentBM>(); ICollection <Apartman> apartments = context.Apartmans.Where(x => x.HostID == hostId && x.Deleted == false).ToList(); foreach (var apartment in apartments) { ApartmentBM apartmentBM = GetApartmentInfo(apartment); apartmentsInfo.Add(apartmentBM); } return(Ok(apartmentsInfo)); }
public IHttpActionResult GetSearchApartments(SearchApartment apartmentDetails) { ICollection <Apartman> apartments = null; if (CheckRole("Admin")) { apartments = GetFiltredApartments(apartmentDetails, "Status"); } else { apartments = GetFiltredApartments(apartmentDetails, ""); } List <ApartmentBM> apartmentsInfo = new List <ApartmentBM>(); foreach (var apartment in apartments) { ApartmentBM apartmentBM = GetApartmentInfo(apartment); apartmentsInfo.Add(apartmentBM); } return(Ok(apartmentsInfo)); }
private ApartmentBM GetApartmentInfo(Apartman apartman) //za sve GET Apartments { ApartmentBM apartmentBM = new ApartmentBM(); apartmentBM.ID = apartman.ID; apartmentBM.Type = apartman.Type.ToString(); apartmentBM.Status = apartman.Status.ToString(); apartmentBM.SingUpTime = apartman.SingUpTime; apartmentBM.SingOutTime = apartman.SingOutTime; apartmentBM.RoomNumber = apartman.RoomNumber; // apartmentBM.RentDates = apartman.RentDates; apartmentBM.PricePerNight = apartman.PricePerNight; apartmentBM.GuestNumber = apartman.GuestNumber; //location info: Location locationInfo = context.Locations.Where(x => x.ID == apartman.LocationID).FirstOrDefault(); apartmentBM.Latitude = locationInfo.Latitude; apartmentBM.Longitude = locationInfo.Longitude; //Coments into: apartmentBM.CommentIDs = new HashSet <int>(); ICollection <Comment> comms = apartman.Comments; // wokrs if (comms != null) { foreach (var comment in comms) { apartmentBM.CommentIDs.Add(comment.ID); } } //Amenities into: apartmentBM.Amenities = new HashSet <string>(); ICollection <Amenitie> amms = apartman.Amenities; // wokrs if (amms != null) { foreach (var amm in amms) { apartmentBM.Amenities.Add(amm.Name); } } //Adress apartmentBM.Streat = locationInfo.Adress.Streat; apartmentBM.StreatNumber = locationInfo.Adress.StreatNumber; apartmentBM.ZipCode = locationInfo.Adress.ZipCode; apartmentBM.Settlement = locationInfo.Adress.Settlement; //Host: User Host = context.Users.Where(x => x.ID == apartman.HostID).FirstOrDefault(); apartmentBM.HostID = Host.ID; apartmentBM.HostName = Host.Name; apartmentBM.HostSurname = Host.Surname; //pictures if (apartman.Pictures != null && apartman.Pictures != "") { apartmentBM.Pictures = new List <string>(); string[] pictures = apartman.Pictures.Split(';'); for (int i = 0; i < pictures.Length; i++) { // byte[] imageBits = System.IO.File.ReadAllBytes(@"D:\Fax\6.Semestar\Web\Projekat\AirBnb_Web1\AirBnb_Web1\Resource\Images\BodyPart_ae1d3ad9-2b71-4222-8517-4821aa41f3ef.jpg"); //string imageBase64 = Convert.ToBase64String(imageBits); if (pictures[i] != "") { apartmentBM.Pictures.Add("http://localhost:8080/" + pictures[i]); } } } //RentDates: ICollection <DatesModel> datesModels = context.DatesModels.Where(x => x.ApartmanID == apartman.ID && x.Available == true && x.Deleted == false).ToList(); if (datesModels != null && datesModels.Count > 0) { if (apartmentBM.RentDates == null) { apartmentBM.RentDates = new HashSet <DateTime>(); } foreach (DatesModel dateModel in datesModels) { apartmentBM.RentDates.Add(dateModel.RentDate); } } return(apartmentBM); }
private bool GetApartmentFromBM(ApartmentBM apartmentBM) //add apartment { Apartman apartman = new Apartman(); apartman.Type = (apartmentBM.Type == ApartmanType.FullApartman.ToString()) ? ApartmanType.FullApartman : ApartmanType.Room; apartman.Status = ApartmanStatus.NotActive; apartman.HostID = apartmentBM.HostID; //promeni ovaj datetype : apartman.SingUpTime = apartmentBM.SingUpTime; apartman.SingOutTime = apartmentBM.SingOutTime; apartman.RoomNumber = apartmentBM.RoomNumber; apartman.PricePerNight = apartmentBM.PricePerNight; //pics apartman.Pictures = ""; if (apartmentBM.Pictures != null) { foreach (string pic in apartmentBM.Pictures) { apartman.Pictures = pic + ';'; } } apartman.GuestNumber = apartmentBM.GuestNumber; Adress adress1 = new Adress(); adress1.Streat = apartmentBM.Streat; adress1.StreatNumber = apartmentBM.StreatNumber; adress1.ZipCode = apartmentBM.ZipCode; adress1.Settlement = apartmentBM.Settlement; context.Adresss.Add(adress1); context.SaveChanges(); //location info: Location locationInfo = new Location(); locationInfo.Latitude = apartmentBM.Latitude; locationInfo.Longitude = apartmentBM.Longitude; locationInfo.AdressID = adress1.ID; context.Locations.Add(locationInfo); context.SaveChanges(); apartman.LocationID = locationInfo.ID; //Amenities: apartman.Amenities = new List <Amenitie>(); foreach (string amm in apartmentBM.Amenities) { Amenitie amenitie = context.Amenities.Where(x => x.Name == amm).FirstOrDefault(); apartman.Amenities.Add(amenitie); } context.SaveChanges(); apartman.Deleted = false; context.Apartmans.Add(apartman); context.SaveChanges(); //zbog slike mi treba ID: apartmentBM.ID = apartman.ID; return(true); }