public void AddCity([FromBody] CityModel model)
 {
     if (ModelState.IsValid)
     {
         if (model.Id == 0)
         {
             City city = new City()
             {
                 Id        = model.Id,
                 Name      = model.Name,
                 CountryId = model.CountryId,
                 IsDeleted = false
             };
             db.Cities.Add(city);
         }
         if (model.Id != 0)
         {
             City city = db.Cities.FirstOrDefault(x => x.Id == model.Id);
             city.Name            = model.Name;
             city.CountryId       = model.CountryId;
             db.Entry(city).State = EntityState.Modified;
         }
         db.SaveChanges();
     }
 }
Ejemplo n.º 2
0
 public void AddAirport([FromBody] AirportModel model)
 {
     if (ModelState.IsValid)
     {
         if (model.Id == 0)
         {
             Airport airport = new Airport()
             {
                 Id        = model.Id,
                 Name      = model.Name,
                 Code      = model.Code,
                 CityId    = model.CityId,
                 IsDeleted = false
             };
             db.Airports.Add(airport);
         }
         if (model.Id != 0)
         {
             Airport airport = db.Airports.FirstOrDefault(x => x.Id == model.Id);
             airport.Name            = model.Name;
             airport.Code            = model.Code;
             airport.CityId          = model.CityId;
             db.Entry(airport).State = EntityState.Modified;
         }
         db.SaveChanges();
     }
 }
Ejemplo n.º 3
0
        public IHttpActionResult DeleteTour([FromBody] int id)
        {
            Tour tour = db.Tours.Find(id);

            tour.IsDeleted = true;

            db.Entry(tour).State = EntityState.Modified;
            db.SaveChanges();
            return(Ok());
        }
        public IHttpActionResult AddPhotos(int id)
        {
            var    keys = System.Web.HttpContext.Current.Request.Files.AllKeys;
            string path = AppDomain.CurrentDomain.BaseDirectory + "static\\Content\\img\\Hotels\\Hotel" + id + "\\";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            foreach (var key in keys)
            {
                var    picture = System.Web.HttpContext.Current.Request.Files[key];
                string imgpath = path + picture.FileName;

                WebImage img = new WebImage(picture.InputStream);
                if (img.Width > 600 || img.Height > 350)
                {
                    img.Resize(600, 350, false, true);
                }
                img.Save(imgpath);

                HotelPhoto hotelPhoto = new HotelPhoto();
                hotelPhoto.PhotoLink = String.Format("../../static/Content/img/Hotels/Hotel{0}/{1}", id, picture.FileName);
                hotelPhoto.HotelId   = id;
                db.HotelsPhotos.Add(hotelPhoto);
                db.SaveChanges();
            }
            return(Ok());
        }
        public IHttpActionResult Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                Utils utils = new Utils();
                var   user  = GetPersonByEmail <User>(model.Email);

                if (user != null)
                {
                    ModelState.AddModelError("", "user with such email already exists");
                    return(BadRequest(ModelState));
                }

                user = new User()
                {
                    Email = model.Email, Password = utils.GetEncodedHash(model.Password, Security.solt), Role = db.Roles.Find(1)
                };
                var customer = new Customer()
                {
                    Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, DateOfBirth = model.DateOfBirth, PhoneNumber = model.PhoneNumber
                };
                db.Users.Add(user);
                db.Customers.Add(customer);
                db.SaveChanges();
                utils.AddUserInCookies(user, AuthenticationManager);
                return(Ok());
            }

            return(BadRequest(ModelState));
        }
        public IHttpActionResult EditCustomer(Customer editCustomer)
        {
            if (ModelState.IsValid)
            {
                var  customer = db.Customers.Find(GetCustomer(User.Identity.Name).Id);
                User user     = db.Users.Include(u => u.Role).FirstOrDefault(u => u.Email == customer.Email);

                if (user != null && User.Identity.Name != editCustomer.Email)
                {
                    ModelState.AddModelError("", "user with such email already exists");
                    return(BadRequest(ModelState));
                }
                customer.FirstName       = editCustomer.FirstName;
                customer.LastName        = editCustomer.LastName;
                customer.PhoneNumber     = editCustomer.PhoneNumber;
                customer.DateOfBirth     = editCustomer.DateOfBirth;
                customer.Email           = editCustomer.Email;
                db.Entry(customer).State = EntityState.Modified;
                user.Email           = editCustomer.Email;
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();

                Utils utils = new Utils();
                utils.AddUserInCookies(user, AuthenticationManager);
                return(Ok());
            }

            return(BadRequest(ModelState));
        }
 public void AddCountry(CountryModel model)
 {
     if (model.Id == 0)
     {
         Country country = new Country()
         {
             Id        = model.Id,
             Name      = model.Name,
             IsDeleted = false
         };
         db.Coutries.Add(country);
     }
     if (model.Id != 0)
     {
         Country country = db.Coutries.FirstOrDefault(x => x.Id == model.Id);
         country.Name            = model.Name;
         db.Entry(country).State = EntityState.Modified;
     }
     db.SaveChanges();
 }
Ejemplo n.º 8
0
 private void AddCountriesForManager(SevenWondersContext db, Manager manager, int[] countries)
 {
     if (manager.Countries != null)
     {
         foreach (var country in manager.Countries.ToList())
         {
             country.ManagerId       = null;
             db.Entry(country).State = EntityState.Modified;
         }
     }
     db.SaveChanges();
     if (countries != null)
     {
         var length = countries.Length;
         for (int i = 0; i < length; i++)
         {
             var country = db.Coutries.Find(countries[i]);
             country.ManagerId       = manager.Id;
             db.Entry(country).State = EntityState.Modified;
         }
     }
     db.SaveChanges();
 }
        public virtual bool ChangePersonStatus(SevenWondersContext db, int id)
        {
            DbSet <T> dbSet    = db.Set <T>();
            var       result   = false;
            var       customer = dbSet.Find(id);

            if (customer != null)
            {
                customer.IsDeleted       = !customer.IsDeleted;
                db.Entry(customer).State = EntityState.Modified;
                result = true;
                db.SaveChanges();
            }
            return(result);
        }
        public void AddFlight([FromBody] EditFlightModel model)
        {
            Airplane airplane = new Airplane()
            {
                Model       = model.airplaneModel,
                Company     = model.airplaneCompany,
                SeatsAmount = model.seatsAmount,
                IsDeleted   = false
            };

            Flight flight = new Flight()
            {
                Number             = model.number,
                Price              = model.price,
                DepartureAirportId = model.departureAirportId,
                ArrivalAirportId   = model.arrivalAirportId,
                Airplane           = airplane,
                AirplaneId         = airplane.Id
            };

            db.Airplanes.Add(flight.Airplane);
            db.Flights.Add(flight);
            db.SaveChanges();
        }
Ejemplo n.º 11
0
        public void EditFullManager(SevenWondersContext db, FullManagerViewModel user, int[] countries)
        {
            Manager manager    = db.Managers.Find(user.Id);
            var     userFromDb = db.Users.FirstOrDefault(x => x.Email == manager.Email);

            manager.LastName        = user.LastName;
            manager.FirstName       = user.FirstName;
            manager.Email           = user.Email;
            manager.PhoneNumber     = user.PhoneNumber;
            manager.DateOfBirth     = user.DateOfBirth;
            db.Entry(manager).State = EntityState.Modified;
            db.SaveChanges();

            Utils utils = new Utils();

            if (user.Password != userFromDb.Password)
            {
                userFromDb.Password = utils.GetEncodedHash(user.Password, Security.solt);
            }
            userFromDb.Email = user.Email;
            AddCountriesForManager(db, manager, countries);
            db.Entry(userFromDb).State = EntityState.Modified;
            db.SaveChanges();
        }
Ejemplo n.º 12
0
        public IHttpActionResult BookTour([FromBody] TourForBookingModel model)
        {
            try
            {
                Room     room           = db.Rooms.Find(model.RoomId);
                Schedule leaveSchedule  = db.Schedule.Find(model.LeaveScheduleId);
                Schedule returnSchedule = db.Schedule.Find(model.ReturnScheduleId);
                decimal  totalPrice
                    = model.Duration * (room.Price + model.PersonAmount * (model.WithoutFood ? 0 : room.Hotel.FoodPrice))
                      + model.PersonAmount * (leaveSchedule.Flight.Price + returnSchedule.Flight.Price);
                Reservation reservation = new Reservation()
                {
                    RoomId           = model.RoomId,
                    PersonAmount     = model.PersonAmount,
                    LeaveScheduleId  = model.LeaveScheduleId,
                    ReturnScheduleId = model.ReturnScheduleId,
                    LeaveDate        = model.LeaveDate,
                    ReturnDate       = model.LeaveDate.AddDays(model.Duration),
                    IsDeleted        = false,
                    WithoutFood      = model.WithoutFood
                };
                Tour tour = new Tour()
                {
                    Reservation   = reservation,
                    ReservationId = reservation.Id,
                    CreationDate  = DateTime.Now,
                    TotalPrice    = totalPrice,
                    TourStateId   = 1,
                    IsDeleted     = false,
                    CustomerId    = getCustomer(User.Identity.Name).Id
                };

                db.Reservations.Add(tour.Reservation);
                db.Tours.Add(tour);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                int i = 1 + 1;
            }
            return(Ok());
        }
Ejemplo n.º 13
0
        public void AddFullManager(SevenWondersContext db, FullManagerViewModel user, int[] countries)
        {
            if (db.Users.Any(x => x.Email == user.Email))
            {
                throw new OverflowException("user with this email is already exist");
            }
            Utils  utils    = new Utils();
            string password = utils.GetEncodedHash(user.Password, Security.solt);

            db.Users.Add(new User()
            {
                Email = user.Email, Password = password, RoleId = 3
            });
            Manager manager = new Manager()
            {
                DateOfBirth = user.DateOfBirth.ToUniversalTime(), FirstName = user.FirstName, LastName = user.LastName, PhoneNumber = user.PhoneNumber, Email = user.Email, IsDeleted = false
            };

            db.Managers.Add(manager);
            db.SaveChanges();
            AddCountriesForManager(db, manager, countries);
        }
Ejemplo n.º 14
0
 public void Save()
 {
     context.SaveChanges();
 }