public async Task <ActionResult> Index(int hotelId, ConfigurationViewModel config) { var roomTypes = db.RoomTypes.Where(c => c.HotelId == hotelId).ToList(); if (ModelState.IsValid) { if (config.RoomTypes.IsEditable) { var newRoomTypes = config.RoomTypes.RoomTypes.Where(c => c.Number == 0).ToList(); if (newRoomTypes.Any()) { db.RoomTypes.AddRange(newRoomTypes.Select(c => new RoomType { Name = c.Name, RoomTypeCode = c.RoomTypeCode, HotelId = hotelId })); } db.RoomTypes.RemoveRange(roomTypes.Where(c => !config.RoomTypes.RoomTypes.Any(s => s.Number == c.Id))); foreach (var item in config.RoomTypes.RoomTypes.Where(c => c.Number > 0).ToList()) { var entity = roomTypes.FirstOrDefault(c => c.Id == item.Number); if (entity != null) { entity.RoomTypeCode = item.RoomTypeCode; entity.Name = item.Name; db.Entry(entity).State = EntityState.Modified; } } await db.SaveChangesAsync(); roomTypes = db.RoomTypes.Where(c => c.HotelId == hotelId).ToList(); } HotelSettings hotel = await db.HotelSettings.FindAsync(hotelId); if (config.MealTypes.UseInDynamicCalculation) { config.RoomTypes.RoomTypeCoefs.Clear(); } hotel.Settings = JsonConvert.SerializeObject(ConfigurationViewModel.Map(config, roomTypes), Formatting.Indented); db.Entry(hotel).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index", "HotelSettings")); } ViewBag.HotelId = hotelId; var mealTypes = db.MealTypes.ToList(); ViewBag.DbMealTypes = new SelectList(mealTypes, "Id", "Name"); ViewBag.DbRoomTypes = new SelectList(roomTypes, "RoomTypeCode", "Name"); return(View(config)); }
public async Task <IActionResult> PutProvince(int id, Province province) { if (id != province.Id) { return(BadRequest()); } _context.Entry(province).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProvinceExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutBaseInfo(int id, BaseInfo baseInfo) { if (id != baseInfo.Id) { return(BadRequest()); } _context.Entry(baseInfo).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BaseInfoExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult> Edit([Bind(Include = "Id,RoomTypeId,MealTypeId,HotelId,RoomName,PeopleNum,Cancelation,Prepayment,City,HotelName,MealName")] Parser_RoomInfo parser_RoomInfo) { if (ModelState.IsValid) { db.Entry(parser_RoomInfo).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index", new { hotelId = parser_RoomInfo.HotelId })); } HotelSettings hotel = db.HotelSettings.Find(parser_RoomInfo.HotelId); DefoConfiguration conf = new DefoConfiguration(hotel.Settings); var roomTypes = db.RoomTypes.Where(c => c.HotelId == parser_RoomInfo.HotelId).ToList(); ViewBag.RoomTypes = new SelectList(roomTypes, "Id", "Name"); if (conf?.ConfigurationRoot?.MealTypes?.MealTypeDescriptions != null) { var mealIds = conf?.ConfigurationRoot?.MealTypes?.MealTypeDescriptions.Select(c => c.Number); if (mealIds.Any()) { var mealTypes = db.MealTypes.Where(c => mealIds.Contains(c.Id)).ToList(); ViewBag.MealTypes = new SelectList(mealTypes, "Id", "Name"); } } return(View(parser_RoomInfo)); }
public void Run(int hotelId) { using (var context = new RmsDbContext()) { HotelSettings hotel = context.HotelSettings.Find(hotelId); if (hotel == null || !hotel.IsRmsEnalbed) { RecurringJob.RemoveIfExists(GetJobName(hotelId)); return; } if (string.IsNullOrWhiteSpace(hotel.Settings)) { context.Logs.Add(new Log { LogType = LogType.Error, CreatedOn = DateTime.Now, Body = "Configuration not found.", HotelId = hotelId }); context.SaveChanges(); return; } var info = context.Parser_RoomInfos.Where(c => c.HotelId == hotelId).ToList(); if (!info.Any()) { context.Logs.Add(new Log { LogType = LogType.Error, CreatedOn = DateTime.Now, Body = "Parser hotel configuration not found.", HotelId = hotelId }); context.SaveChanges(); return; } try { IParserAdapter parserAdapter = new ParserAdapter(); var calculatedOn = DateTime.Now; double rating = 0.0; var result = parserAdapter.Run(calculatedOn, hotel.PlanningHorizon, info, hotel.Settings, hotel.BookingName, out rating).ToList(); if (result.Any()) { context.Parser_RoomDatas.AddRange(result); context.Logs.Add(new Log { LogType = LogType.Info, CreatedOn = DateTime.Now, Body = "New booking data have been successfully obtained.", HotelId = hotelId }); hotel.BookingRating = rating; context.Entry(hotel).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } } catch (Exception ex) { context.Logs.Add(new Log { LogType = LogType.Error, CreatedOn = DateTime.Now, Body = ex.Message + Environment.NewLine + ex.InnerException?.Message, HotelId = hotelId }); context.SaveChanges(); throw; } } }
public async Task <ActionResult> Edit([Bind(Include = "Id,Name,Settings,IsRmsEnalbed,IsNeedRecalc")] HotelSettings hotel) { if (ModelState.IsValid) { HotelSettings hotelUp = await db.HotelSettings.FindAsync(hotel.Id); hotelUp.Name = hotel.Name; hotelUp.IsNeedRecalc = hotel.IsNeedRecalc; hotelUp.IsRmsEnalbed = hotel.IsRmsEnalbed; hotelUp.Settings = hotel.Settings; db.Entry(hotelUp).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(hotel)); }
public async Task <bool> UpdateEvents(IEnumerable <Event> events) { using (var context = new RmsDbContext()) { if (events.Any()) { foreach (var item in events) { context.Entry(item).State = EntityState.Modified; } HotelSettings hotel = await context.HotelSettings.FindAsync(events.FirstOrDefault().HotelId); hotel.IsNeedRecalc = true; await context.SaveChangesAsync(); } return(true); } }