Beispiel #1
0
 public HotelViewModel EditHotel(int id, HotelViewModel hvmodel)
 {
     using (HotelmanagementEntities db = new HotelmanagementEntities())
     {
         var h = db.hotels.FirstOrDefault(p => p.hotelid == id);
         if (h == null)
         {
             return(null);
         }
         else
         {
             h.hotelname     = hvmodel.hotelname;
             h.address       = hvmodel.address;
             h.city          = hvmodel.city;
             h.pincode       = hvmodel.pincode;
             h.contactnumber = hvmodel.contactnumber;
             h.contactperson = hvmodel.contactperson;
             h.website       = hvmodel.website;
             h.facebook      = hvmodel.facebook;
             h.twitter       = hvmodel.twitter;
             h.isactive      = hvmodel.isactive;
             h.isdelete      = hvmodel.isdelete;
             h.createddate   = hvmodel.createddate;
             h.createdby     = hvmodel.createdby;
             db.SaveChanges();
             return(hvmodel);
         }
     }
 }
 public bool BookRoom(int roomId, DateTime date)
 {
     using (HotelmanagementEntities db = new HotelmanagementEntities())
     {
         bool status = false;
         try
         {
             booking temp = db.bookings.Where(x => x.roomid == roomId && x.bookingdate == date).FirstOrDefault();
             if (temp != null)
             {
                 return(status);
             }
             booking booking = new booking {
                 roomid = roomId, bookingdate = date, bookingstatus = "optional"
             };
             db.bookings.Add(booking);
             if (db.SaveChanges() > 0)
             {
                 status = true;
             }
             return(status);
         }
         catch (Exception e)
         {
             Console.WriteLine(e.Message);
             return(false);
         }
     }
 }
Beispiel #3
0
 public void DeleteHotel(int id)
 {
     using (HotelmanagementEntities db = new HotelmanagementEntities())
     {
         hotel h = db.hotels.Where(p => p.hotelid == id).FirstOrDefault();
         db.Entry(h).State = System.Data.Entity.EntityState.Deleted;
         db.SaveChanges();
     }
 }
 public RoomsViewModel AddRooms(RoomsViewModel rvmodel)
 {
     using (HotelmanagementEntities db = new HotelmanagementEntities())
     {
         room r      = new room();
         var  config = new MapperConfiguration(cfg =>
         {
             cfg.CreateMap <RoomsViewModel, room>();
         });
         IMapper mapper = config.CreateMapper();
         r = mapper.Map <RoomsViewModel, room>(rvmodel);
         db.rooms.Add(r);
         db.SaveChanges();
         return(rvmodel);
     }
 }
Beispiel #5
0
 public HotelViewModel AddHotel(HotelViewModel hvmodel)
 {
     using (HotelmanagementEntities db = new HotelmanagementEntities())
     {
         hotel h      = new hotel();
         var   config = new MapperConfiguration(cfg =>
         {
             cfg.CreateMap <HotelViewModel, hotel>();
         });
         IMapper mapper = config.CreateMapper();
         h = mapper.Map <HotelViewModel, hotel>(hvmodel);
         db.hotels.Add(h);
         db.SaveChanges();
         return(hvmodel);
     }
 }
 public bool DeleteBooking(int bookingId)
 {
     using (HotelmanagementEntities db = new HotelmanagementEntities())
     {
         bool status = false;
         try
         {
             booking booking = db.bookings.Where(x => x.bookingid == bookingId).AsNoTracking().FirstOrDefault();
             booking.bookingstatus   = "Deleted";
             db.Entry(booking).State = EntityState.Modified;
             if (db.SaveChanges() > 0)
             {
                 status = true;
             }
             return(status);
         }
         catch (Exception e)
         {
             Console.WriteLine(e.Message);
             return(false);
         }
     }
 }
 public bool UpdateBookingStatus(int id, string status)
 {
     using (HotelmanagementEntities db = new HotelmanagementEntities())
     {
         bool updated = false;
         try
         {
             booking booking = db.bookings.AsNoTracking().Where(x => x.bookingid == id).FirstOrDefault();
             booking.bookingstatus   = status;
             db.Entry(booking).State = EntityState.Modified;
             if (db.SaveChanges() > 0)
             {
                 updated = true;
             }
             return(updated);
         }
         catch (Exception e)
         {
             Console.WriteLine(e.Message);
             return(false);
         }
     }
 }