public IHttpActionResult PutFacility(int id, Facility facility)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != facility.Facility_No)
            {
                return(BadRequest());
            }

            db.Entry(facility).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FacilityExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 2
0
        public IHttpActionResult PutBooking(int id, Booking booking)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != booking.Booking_id)
            {
                return(BadRequest());
            }

            db.Entry(booking).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BookingExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutRoom(int id, Room room)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != room.Room_No)
            {
                return(BadRequest());
            }

            db.Entry(room).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RoomExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public ActionResult Create([Bind(Include = "OrderID,FullName,Date,Phone,IdentifyDocument,Deposit,Deleted")] Order order)
        {
            if (ModelState.IsValid)
            {
                db.Orders.Add(order);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(order));
        }
 public ActionResult Edit([Bind(Include = "ID,OrderID,RoomID,Fromdate,ToDate,Price")] OrderDetail orderDetail)
 {
     if (ModelState.IsValid)
     {
         db.Entry(orderDetail).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", new { order = orderDetail.OrderID }));
     }
     ViewBag.OrderID = new SelectList(db.Orders, "OrderID", "FullName", orderDetail.OrderID);
     ViewBag.RoomID  = new SelectList(db.Rooms, "RoomID", "RoomID", orderDetail.RoomID);
     return(View(orderDetail));
 }
Exemplo n.º 6
0
        public string AddBooking(BookingModel model)
        {
            string result = string.Empty;

            using (HotelDBContext _hotelEntities = new HotelDBContext())
            {
                try
                {
                    Booking bookingTbl = new Booking();
                    bookingTbl.InvoiceNumber  = model.InvoiceNumber;
                    bookingTbl.HotelId        = model.HotelId;
                    bookingTbl.RoomId         = model.RoomId;
                    bookingTbl.FromDate       = model.FromDate;
                    bookingTbl.ToDate         = model.ToDate;
                    bookingTbl.BookingDate    = model.BookingDate;
                    bookingTbl.BuyingPrice    = model.BuyingPrice;
                    bookingTbl.BuyingCurrency = model.BuyingCurrency;
                    bookingTbl.CreatedOn      = System.DateTime.Now.ToShortDateString();
                    _hotelEntities.Entry(bookingTbl).State = System.Data.Entity.EntityState.Added;
                    _hotelEntities.SaveChanges();
                    result = "Record Inserted";
                }
                catch (Exception)
                {
                    result = "Failed To Insert";
                }
                return(result);
            }
        }
Exemplo n.º 7
0
        public string AddHotel(HotelModel model)
        {
            string result = string.Empty;

            using (HotelDBContext _hotelEntities = new HotelDBContext())
            {
                try
                {
                    Hotel hotel = new Hotel();
                    hotel.HotelName                   = model.HotelName;
                    hotel.Address                     = model.Address;
                    hotel.CityId                      = model.CityId;
                    hotel.CountryId                   = model.CountryId;
                    hotel.PhoneNumber                 = model.PhoneNumber;
                    hotel.Description                 = model.Description;
                    hotel.CancellationPolicy          = model.CancellationPolicy;
                    hotel.DefaultCurrency             = model.DefaultCurrency;
                    hotel.PricePerNight               = model.PricePerNight;
                    hotel.CreatedOn                   = System.DateTime.Now.ToShortDateString();
                    _hotelEntities.Entry(hotel).State = System.Data.Entity.EntityState.Added;
                    _hotelEntities.SaveChanges();
                    result = "Record Inserted";
                }
                catch (Exception)
                {
                    result = "Failed To Insert";
                }
                return(result);
            }
        }
Exemplo n.º 8
0
        public string UpdateRoom(RoomTypeModel roomType)
        {
            string result = string.Empty;

            using (HotelDBContext _hotelEntities = new HotelDBContext())
            {
                try
                {
                    RoomType roomTbl = new RoomType();
                    roomTbl.Id         = roomType.Id;
                    roomTbl.RoomName   = roomType.RoomName;
                    roomTbl.Amenities  = roomType.Amenities;
                    roomTbl.ImagePath  = roomType.ImagePath;
                    roomTbl.ModifiedOn = System.DateTime.Now.ToShortDateString();
                    _hotelEntities.RoomTypes.Add(roomTbl);
                    _hotelEntities.Entry(roomTbl).State = System.Data.Entity.EntityState.Modified;
                    _hotelEntities.SaveChanges();
                    result = "Record Updated";
                }
                catch (Exception)
                {
                    result = "Failed To Upadate";
                }
                return(result);
            }
        }
Exemplo n.º 9
0
        public ActionResult Create([Bind(Include = "TypeRoomID,NameRoom,Capacity,Price,Description")] TypeRoom typeRoom, HttpPostedFileBase image2)
        {
            if (ModelState.IsValid)
            {
                if (image2 != null)
                {
                    typeRoom.Image = new byte[image2.ContentLength];
                    image2.InputStream.Read(typeRoom.Image, 0, image2.ContentLength);
                }
                db.TypeRooms.Add(typeRoom);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(typeRoom));
        }
Exemplo n.º 10
0
 public void TestMethod1()
 {
     //__MigrationHistory这个表为ef中Code first的编程方式
     //如果通过code first自动生成的数据库,就会存在这个表,这个表存在代码自动生成数据库
     //后续程序启动程序就会判断该表是否存在,如果存在就代码使用的是code first代码创建的数据库
     //如果不存在代表使用的是code first数据库优先的方式
     //两种模式不可混用
     //以下代码在数据库不存在的情况下,可自动创建数据库表
     //一旦数据实体更改增加字段,那么就需要采用ef数据迁移的方式更新数据库
     //就算手动更新了数据库,增加了字段,保证了与实体的一致也达不到效果,也将报错
     //可以删除__MigrationHistory表,代表采用的是code first中的数据库优先,这时保证数据库接口与实体的结构一直就可以保存成功
     try
     {
         UserInfo u = new UserInfo()
         {
             Id        = "2",
             UserCode  = "1",
             UserName  = "******",
             PassWord  = "******",
             PassWord3 = "2",
             PassWord4 = "2"
         };
         using (HotelDBContext contenxt = new HotelDBContext())
         {
             contenxt.customer.Add(u);
             contenxt.SaveChanges();
         }
     }
     catch (Exception e)
     {
     }
 }
Exemplo n.º 11
0
        public string AddTraveller(TravellerModel travellerModel)
        {
            string result = string.Empty;

            using (HotelDBContext travellerEntities = new HotelDBContext())
            {
                try
                {
                    Traveller traveller = new Traveller();
                    traveller.FirstName    = travellerModel.FirstName;
                    traveller.MiddleName   = travellerModel.MiddleName;
                    traveller.LastName     = travellerModel.LastName;
                    traveller.MobileNo     = travellerModel.MobileNo;
                    traveller.EmailId      = travellerModel.EmailId;
                    traveller.Gender       = travellerModel.Gender;
                    traveller.Address      = travellerModel.Address;
                    traveller.FirstName_2  = travellerModel.FirstName_2;
                    traveller.MiddleName_2 = travellerModel.MiddleName_2;
                    traveller.LastName_2   = travellerModel.LastName_2;
                    traveller.CreatedOn    = System.DateTime.Now.ToShortDateString();
                    travellerEntities.Entry(traveller).State = System.Data.Entity.EntityState.Added;
                    travellerEntities.SaveChanges();
                    result = "Record Inserted";
                }
                catch (Exception ex)
                {
                    Log.Error("Failed To Insert", ex);
                    result = "Failed To Insert";
                }
                return(result);
            }
        }
Exemplo n.º 12
0
        public string AddPayment(PaymentModel model)
        {
            string result = string.Empty;

            using (HotelDBContext dBEntities = new HotelDBContext())
            {
                try
                {
                    Payment paymentTbl = new Payment();
                    paymentTbl.BookingId  = model.BookingId;
                    paymentTbl.CardNumber = model.CardNumber;
                    paymentTbl.NameOnCard = model.NameOnCard;
                    paymentTbl.ExpiryDate = model.ExpiryDate;
                    paymentTbl.Status     = model.Status;
                    paymentTbl.CreatedOn  = System.DateTime.Now.ToShortDateString();
                    dBEntities.Entry(paymentTbl).State = System.Data.Entity.EntityState.Added;
                    dBEntities.SaveChanges();
                    result = "Record Inserted";
                }
                catch (Exception)
                {
                    result = "Failed To Insert";
                }
                return(result);
            }
        }
Exemplo n.º 13
0
 public bool Delete(int id)
 {
     try
     {
         var roomToDelete = _context.Rooms.FirstOrDefault(s => s.RoomId == id);
         if (roomToDelete is not null)
         {
             _context.Rooms.Remove(roomToDelete);
             _context.SaveChanges();
             return(true);
         }
         return(false);
     }
     catch (Exception)
     {
         throw;
     }
 }
        public ActionResult Create([Bind(Include = "RoomID,TypeRoomID,CanUse,Image")] Room room)
        {
            if (ModelState.IsValid)
            {
                foreach (var item in db.Rooms)
                {
                    if (item.RoomID.Trim().Equals(room.RoomID.Trim()))
                    {
                        ModelState.AddModelError("RoomID", "ID is exist");
                        ViewBag.TypeRoomID = new SelectList(db.TypeRooms, "TypeRoomID", "NameRoom", room.TypeRoomID);
                        return(View(room));
                    }
                }
                db.Rooms.Add(room);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.TypeRoomID = new SelectList(db.TypeRooms, "TypeRoomID", "NameRoom", room.TypeRoomID);
            return(View(room));
        }
Exemplo n.º 15
0
 public IActionResult SignIn(User user)
 {
     if (ModelState.IsValid)
     {
         var entity = db.User.FirstOrDefault(i => i.EmailAddress == user.EmailAddress);
         if (entity == null)
         {
             db.User.Add(user);
             db.SaveChanges();
             return(RedirectToAction("Login", "Account"));
         }
         else
         {
             ModelState.AddModelError("", "This user already exist.");
         }
     }
     return(View(user));
 }
Exemplo n.º 16
0
        public HotelComment AddHotelComment(HotelComment hotelcomment)
        {
            var context = new HotelDBContext();

            try
            {
                if (hotelcomment.Id == 0)
                {
                    context.HotelComment.Add(hotelcomment);
                }
                context.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return(hotelcomment);
        }
Exemplo n.º 17
0
        public string DeleteHotel(int id)
        {
            string result = string.Empty;

            using (HotelDBContext _hotelEntities = new HotelDBContext())
            {
                try
                {
                    Hotel hotel = _hotelEntities.Hotels.Where(x => x.Id == id).FirstOrDefault <Hotel>();
                    _hotelEntities.Hotels.Remove(hotel);
                    _hotelEntities.SaveChanges();
                    result = "Record deleted";
                }
                catch (Exception)
                {
                    result = "Record failed to delete";
                }

                return(result);
            }
        }
Exemplo n.º 18
0
 public void Save()
 {
     _context.SaveChanges();
 }
Exemplo n.º 19
0
 //Zapisuje do bazy nowe hotele wraz z pokojami
 public void UploadHotels(HotelModel hotel)
 {
     _context.Update(hotel);
     _context.SaveChanges();
 }