public string CreateRoom(Room room) { try { if (room != null) { Database.Room entity = new Database.Room(); entity.HotelID = room.HotelID; entity.RoomName = room.RoomName; entity.RoomCategory = room.RoomCategory; entity.RoomPrice = room.RoomPrice; entity.IsActive = true; entity.CreatedDate = DateTime.Now; entity.CreatedBy = room.CreatedBy; _dbContext.Rooms.Add(entity); _dbContext.SaveChanges(); return("Added succeffuly"); } return("Model is null"); } catch (Exception ex) { return(ex.Message); } }
public Room GetRoom(int id) { try { Database.Room room = _dbContext.Rooms.Include(b => b.Bookings).Where(r => r.Id == id).Single(); return(_mapper.Map <Database.Room, Room>(room)); } catch (Exception exception) { return(null); throw; } }
public string CreateRoom(Room room) { try { Database.Room entry = _mapper.Map <Database.Room>(room); entry.CreatedDate = DateTime.Today; entry.CreatedBy = 1; _dbContext.Rooms.Add(entry); _dbContext.SaveChanges(); return("Success"); } catch (Exception e) { return(e.Message); } }
private void LoadProducts(int id) { Database.Room room = _rentSiteContext.Room.Find(id); if (room == null) { return; } List <Database.Room> listOfSimilarRooms = _rentSiteContext.Room.Where(x => x.Rented == false && x.Id != id && x.CityId == room.CityId).ToList(); //oni koji su razlicii i oni koji dolaze iz istog grada List <Database.RoomReview> marks; foreach (Database.Room room1 in listOfSimilarRooms) { marks = _rentSiteContext.RoomReview.Where(x => x.RoomId == room1.Id).OrderBy(x => x.UserId).ToList(); if (marks.Count > 0) { products.Add(room1.Id, marks); } } }
public string CreateRoom(Room model) { try { if (model != null) { Database.Room entity = new Database.Room(); var config = new MapperConfiguration(cfg => cfg.CreateMap <Room, Database.Room>()); var Mapper = new Mapper(config); entity = Mapper.Map <Database.Room>(model); entity.CreatedDate = DateTime.Now; _dbContext.Rooms.Add(entity); _dbContext.SaveChanges(); return("Successfully Added!"); } return("Model Is Null!"); } catch (Exception ex) { return(ex.Message); } }
// POST hotels public Models.Hotel AddHotel(Models.Hotel hotel) { Database.Hotel model = new Database.Hotel(); model.Address = hotel.Address; model.City = hotel.City; model.ContactNo = hotel.ContactNo; model.ContactPerson = hotel.ContactPerson; model.CreatedBy = hotel.CreatedBy; model.CreatedDate = hotel.CreatedDate; model.facebook = hotel.facebook; model.IsActive = hotel.IsActive; model.Name = hotel.Name; model.PinCode = hotel.PinCode; model.Twitter = hotel.Twitter; model.UpdatedBy = hotel.UpdatedBy; model.UpdatedDate = hotel.UpdatedDate; model.Website = hotel.Website; model.Rooms = new List <Database.Room>(); foreach (var item in hotel.Rooms) { Database.Room rooms = new Database.Room(); // rooms.HotelId = item.HotelId; rooms.Name = item.Name; rooms.Category = item.Category; rooms.Price = item.Price; rooms.IsActive = item.IsActive; rooms.CreatedBy = item.CreatedBy; rooms.CreatedDate = DateTime.Today; rooms.UpdatedBy = item.UpdatedBy; rooms.UpdatedDate = DateTime.Today; model.Rooms.Add(rooms); } var result = context.Hotels.Add(model); context.SaveChanges(); return(hotel); }