public async Task <bool> Add(string name)
        {
            if (await Exist(name))
            {
                var items = await context.Amenities.ToListAsync();

                var item = items.First(x => x.Name == name);
                if (item.IsDeleted)
                {
                    item.IsDeleted = false;
                    foreach (var it in items)
                    {
                        if (it.Name == name)
                        {
                            it.IsDeleted = false;
                        }
                    }
                    await context.SaveChangesAsync();

                    return(true);
                }
                return(false);
            }
            else
            {
                var newItem = new Amenitie()
                {
                    IsDeleted = false, Name = name
                };
                context.Amenities.Add(newItem);
                await context.SaveChangesAsync();

                return(true);
            }
        }
        public IHttpActionResult AddAmenitie(string amenitieName)
        {
            if (CheckRole("Admin"))
            {
                return(StatusCode(HttpStatusCode.Unauthorized));
            }

            Amenitie amm = context.Amenities.Where(x => x.Name == amenitieName && x.Deleted == false).FirstOrDefault();

            if (amm == null)
            {
                Amenitie am1 = new Amenitie();
                am1.Deleted = false;
                am1.Name    = amenitieName;

                context.Amenities.Add(am1);
                context.SaveChanges();
                return(Ok());
            }

            else
            {
                return(BadRequest("Amenitie already exists"));
            }
        }
        protected override void Seed(AirBnbContext context)
        {
            Adress adress1 = new Adress();

            adress1.ID           = 1;
            adress1.Streat       = "Bulevar Oslobodjenja";
            adress1.StreatNumber = 30;
            adress1.ZipCode      = 21000;
            adress1.Settlement   = "Novi Sad";
            context.Adresss.Add(adress1);
            context.SaveChanges();

            Amenitie amenitie1 = new Amenitie();

            amenitie1.Name = "Klima";
            context.Amenities.Add(amenitie1);
            context.SaveChanges();

            Location location1 = new Location();

            location1.ID        = 1;
            location1.Latitude  = 45.23;
            location1.Longitude = 25.23;
            location1.AdressID  = 1;

            User user1 = new User {
                ID = 1, Name = "Sasa", Surname = "Dragomirovic", Gender = Helper.Enums.Genders.Male, Password = "******", Role = Helper.Enums.Roles.Admin, UserName = "******"
            };
            User user2 = new User {
                ID = 2, Name = "Biba", Surname = "Bibic", Gender = Helper.Enums.Genders.Male, Password = "******", Role = Helper.Enums.Roles.Guest, UserName = "******"
            };
            User user3 = new User {
                ID = 3, Name = "Gruja", Surname = "Grujic", Gender = Helper.Enums.Genders.Male, Password = "******", Role = Helper.Enums.Roles.Host, UserName = "******"
            };

            context.Users.Add(user1);
            context.Users.Add(user2);
            context.Users.Add(user3);
            context.SaveChanges();

            Apartman apartman1 = new Apartman {
                ID = 1, GuestNumber = 3, HostID = 3, LocationID = 1, PricePerNight = 20, RoomNumber = 2
            };

            context.Apartmans.Add(apartman1);
            context.SaveChanges();

            Comment comment1 = new Comment {
                ID = 1, ApartmanID = 1, GuestID = 2, Rate = 9.5, Text = "Nice one"
            };

            context.Comments.Add(comment1);
            context.SaveChanges();

            //Reservation reservation1 = new Reservation { ID = 1, ApartmanID = 1, GuestID = 2, NumberOfNights = 10, SingUpDate = DateTime.Now, Stauts = Helper.Enums.ReservationStatus.Accepted, TotalPrice = 100 };
            //context.Reservations.Add(reservation1);
            //context.SaveChanges();
        }
        public IHttpActionResult DeleteAmenitie(int amenitieId)
        {
            if (CheckRole("Admin"))
            {
                return(StatusCode(HttpStatusCode.Unauthorized));
            }

            Amenitie amm = context.Amenities.Where(x => x.ID == amenitieId).FirstOrDefault();

            amm.Deleted = true;
            //context.Amenities.Remove(amm);
            context.SaveChanges();

            return(Ok());
        }
        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);
        }
        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);
        }
        protected override void Seed(AirBnb_Web1.DataAccessLayer.AirBnbContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.



            Adress adress1 = new Adress();

            adress1.ID           = 1;
            adress1.Streat       = "Bulevar Oslobodjenja";
            adress1.StreatNumber = 30;
            adress1.ZipCode      = 21000;
            adress1.Settlement   = "Novi Sad";
            context.Adresss.Add(adress1);
            context.SaveChanges();

            Amenitie amenitie1 = new Amenitie();

            amenitie1.Name = "Klima";
            context.Amenities.Add(amenitie1);
            context.SaveChanges();

            Location location1 = new Location();

            location1.ID        = 1;
            location1.Latitude  = 45.23;
            location1.Longitude = 25.23;
            location1.AdressID  = adress1.ID;
            context.Locations.Add(location1);
            context.SaveChanges();

            User user1 = new User {
                ID = 1, Name = "Sasa", Surname = "Dragomirovic", Gender = Helper.Enums.Genders.Male, Password = "******", Role = Helper.Enums.Roles.Admin, UserName = "******", Blocked = false
            };
            User user2 = new User {
                ID = 2, Name = "Biba", Surname = "Bibic", Gender = Helper.Enums.Genders.Male, Password = "******", Role = Helper.Enums.Roles.Guest, UserName = "******", Blocked = false
            };
            User user3 = new User {
                ID = 3, Name = "Gruja", Surname = "Grujic", Gender = Helper.Enums.Genders.Male, Password = "******", Role = Helper.Enums.Roles.Host, UserName = "******", Blocked = false
            };

            context.Users.Add(user1);
            context.Users.Add(user2);
            context.Users.Add(user3);
            context.SaveChanges();

            Apartman apartman1 = new Apartman {
                ID = 1, SingUpTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 12, 0, 0), SingOutTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 12, 0, 0), Status = Helper.Enums.ApartmanStatus.Active, GuestNumber = 3, HostID = user3.ID, LocationID = location1.ID, PricePerNight = 20, RoomNumber = 2
            };

            context.Apartmans.Add(apartman1);
            context.SaveChanges();

            Comment comment1 = new Comment {
                ID = 1, ApartmanID = apartman1.ID, GuestID = user2.ID, Rate = 9.5, Text = "Nice one"
            };

            context.Comments.Add(comment1);
            context.SaveChanges();

            DatesModel rentDate1 = new DatesModel {
                ID = 1, ApartmanID = apartman1.ID, Available = true, RentDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 12, 0, 0)
            };

            context.DatesModels.Add(rentDate1);
            context.SaveChanges();

            DatesModel rentDate2 = new DatesModel {
                ID = 1, ApartmanID = apartman1.ID, Available = true, RentDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 12, 0, 0)
            };

            context.DatesModels.Add(rentDate2);
            context.SaveChanges();

            DatesModel rentDate3 = new DatesModel {
                ID = 1, ApartmanID = apartman1.ID, Available = true, RentDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 12, 0, 0)
            };

            context.DatesModels.Add(rentDate3);
            context.SaveChanges();

            Reservation reservation1 = new Reservation {
                ID = 1, ApartmanID = apartman1.ID, GuestID = user2.ID, NumberOfNights = 10, SingUpDate = rentDate1.RentDate, Stauts = Helper.Enums.ReservationStatus.Accepted, TotalPrice = 100
            };

            context.Reservations.Add(reservation1);
            context.SaveChanges();

            Reservation reservation2 = new Reservation {
                ID = 2, ApartmanID = apartman1.ID, GuestID = user2.ID, NumberOfNights = 10, SingUpDate = rentDate2.RentDate, Stauts = Helper.Enums.ReservationStatus.Created, TotalPrice = 200
            };

            context.Reservations.Add(reservation2);
            context.SaveChanges();

            Reservation reservation3 = new Reservation {
                ID = 3, ApartmanID = apartman1.ID, GuestID = user2.ID, NumberOfNights = 10, SingUpDate = rentDate3.RentDate, Stauts = Helper.Enums.ReservationStatus.Done, TotalPrice = 200
            };

            context.Reservations.Add(reservation3);
            context.SaveChanges();

            HolidayDays h1 = new HolidayDays {
                Deleted = false, Holiday = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 12, 0, 0)
            };

            context.Holidays.Add(h1);
            context.SaveChanges();
        }