Example #1
0
        /// <summary>
        /// Post inflations
        /// </summary>
        public async Task <IHttpActionResult> Post([FromBody] InflationViewModel[] InflationViewModels)
        {
            using (var context = new RmsDbContext())
            {
                var inflations = Mapper.Map <List <Inflation> >(InflationViewModels);
                inflations.ForEach(s => context.Inflations.RemoveRange(context.Inflations.Where(c => c.CountryId == s.CountryId && c.Date == s.Date)));

                while (inflations.Any())
                {
                    context.Inflations.AddRange(inflations.Take(250));
                    try
                    {
                        await context.SaveChangesAsync();
                    }
                    catch (Exception ex)
                    {
                    }
                    finally
                    {
                        inflations = inflations.Skip(250).ToList();
                    }
                }
            }

            return(Ok());
        }
        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;
                }
            }
        }
Example #3
0
        public StuffsController(RmsDbContext context, IMapper mapper, IStuffService stuffService)
        {
            _context      = context;
            _mapper       = mapper;
            _stuffService = stuffService;

            page           = 1;
            pageSize       = 0;
            recordsPerPage = 50;
            totalItemCount = 0;
        }
Example #4
0
 public void RunHotelsJob()
 {
     using (var context = new RmsDbContext())
     {
         var hotels = context.HotelSettings.Where(h => h.IsRmsEnalbed).ToList();
         foreach (var hotel in hotels)
         {
             RecurringJob.AddOrUpdate <CalculateHotelPredictionTask>(CalculateHotelPredictionTask.GetJobName(hotel.Id), t => t.Run(hotel.Id), Cron.Minutely);
             RecurringJob.AddOrUpdate <BookingParserHotelTask>(BookingParserHotelTask.GetJobName(hotel.Id), t => t.Run(hotel.Id), Cron.Daily);
         }
     }
 }
Example #5
0
        public async Task <bool> InsertEvents(IEnumerable <Event> events)
        {
            using (var context = new RmsDbContext())
            {
                if (events.Any())
                {
                    context.Events.AddRange(events);
                    HotelSettings hotel = await context.HotelSettings.FindAsync(events.FirstOrDefault().HotelId);

                    hotel.IsNeedRecalc = true;
                    await context.SaveChangesAsync();
                }
                return(true);
            }
        }
Example #6
0
        public void CreateMenu_Test()
        {
            var menu = new Menu("TestMenu", "My test menu", "My test menu description", null, MenuLevel.Parent, 1, null, "*****@*****.**");

            //using (var repositoryContext = new EntityFrameworkRepositoryContext(new RmsDbContext("rms")))
            //{
            //    var context = repositoryContext.Context.Set<Menu>();
            //    context.Add(menu);
            //    repositoryContext.Commit();
            //}

            using (var myContext = new RmsDbContext("rms"))
            {
                myContext.Context.Set <Menu>().Add(menu);
                myContext.Context.SaveChanges();
            }
        }
Example #7
0
        public async Task <bool> DeleteEvents(IEnumerable <int> ids)
        {
            using (var context = new RmsDbContext())
            {
                var events = await context.Events.Where(c => ids.Contains(c.Id)).ToListAsync();

                if (events.Any())
                {
                    HotelSettings hotel = await context.HotelSettings.FindAsync(events.FirstOrDefault().HotelId);

                    context.Events.RemoveRange(events);
                    hotel.IsNeedRecalc = true;
                    await context.SaveChangesAsync();
                }
                return(true);
            }
        }
Example #8
0
        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);
            }
        }
Example #9
0
        public async Task <bool> InsertReservations(IEnumerable <Reservation> reservations, int hotelId)
        {
            using (var context = new RmsDbContext())
            {
                HotelSettings hotel = await context.HotelSettings.FindAsync(hotelId);

                if (hotel == null)
                {
                    return(false);
                }

                DateTime createdOn = DateTime.Now;
                reservations.ToList().ForEach(f =>
                {
                    f.HotelId   = hotelId;
                    f.CreatedOn = createdOn;
                });
                while (reservations.Any())
                {
                    context.Reservations.AddRange(reservations.Take(250));
                    try
                    {
                        await context.SaveChangesAsync();
                    }
                    catch (Exception ex)
                    {
                        return(false);
                    }
                    finally
                    {
                        reservations = reservations.Skip(250).ToList();
                    }
                }
                hotel.IsNeedRecalc = true;
                return(true);
            }
        }
Example #10
0
 public ProvincesController(RmsDbContext context)
 {
     _context = context;
 }
Example #11
0
 public ManagementAppMenusController(RmsDbContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Example #12
0
 public HoldingsController(RmsDbContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
 public AssignRequisitionRepository(RmsDbContext db) : base(db)
 {
     _db = db;
 }
        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;
                }

                //Calculation lastCalculation = context.Calculations.Where(c => c.HotelId == hotelId).OrderByDescending(c => c.CalculatedOn).FirstOrDefault();

                //if ((lastCalculation == null && context.Reservations.Any(r => r.HotelId == hotelId)) ||
                //    (lastCalculation != null && context.Reservations.Any(r => r.HotelId == hotelId && r.CreatedOn > lastCalculation.CalculatedOn)))
                if (hotel.IsNeedRecalc)
                {
                    IEnumerable <Reservation> reservations = context.Reservations.Where(r => r.HotelId == hotelId).ToList();
                    IEnumerable <Event>       events       = context.Events.Where(r => r.HotelId == hotelId).ToList();

                    IEnumerable <Parser_RoomData> actualParserData = new List <Parser_RoomData>();
                    if (context.Parser_RoomDatas.Any(r => r.Parser_RoomInfo.HotelId == hotelId))
                    {
                        var lastDate = context.Parser_RoomDatas.Where(r => r.Parser_RoomInfo.HotelId == hotelId).Max(r => r.CreationDate);
                        actualParserData = context.Parser_RoomDatas.Where(r => r.Parser_RoomInfo.HotelId == hotelId && r.CreationDate == lastDate).ToList();
                    }

                    IEnumerable <Inflation> inflations = context.Inflations.ToList();

                    IRmsAdapter rmsAdapter   = new RmsAdapter();
                    string      startDateStr = ConfigurationManager.AppSettings["start_date"];
                    DateTime    startDate    = DateTime.Now;
                    if (!string.IsNullOrEmpty(startDateStr))
                    {
                        startDate = DateTime.ParseExact(startDateStr, "dd.MM.yyyy", null);
                    }
                    var result = rmsAdapter.Run(startDate, hotel.PlanningHorizon, hotel.HistoryPeriod, reservations, inflations, events, actualParserData, hotel.Settings, hotel.BookingRating).ToList();

                    var calculatedOn = DateTime.Now;
                    foreach (Calculation calculation in result)
                    {
                        calculation.CalculatedOn = calculatedOn;
                        calculation.HotelId      = hotel.Id;
                        calculation.Settings     = hotel.Settings;
                    }

                    if (result.Any())
                    {
                        context.Calculations.AddRange(result);
                        context.Logs.Add(new Log {
                            LogType = LogType.Info, CreatedOn = DateTime.Now, Body = "New predictions have been successfully calculated.", HotelId = hotelId
                        });
                        hotel.IsNeedRecalc = false;
                        context.SaveChanges();
                    }
                }
                else
                {
                    context.Logs.Add(new Log {
                        LogType = LogType.Info, CreatedOn = DateTime.Now, Body = "New data not found for calculate predictions.", HotelId = hotelId
                    });
                    context.SaveChanges();
                }
            }
        }
Example #15
0
 public WebHooksController(RmsDbContext context) : base(context)
 {
 }
Example #16
0
 public StuffGroupsController(RmsDbContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Example #17
0
        public async Task <RmsAdapter> InitRmsAdapter(DateTime start, DateTime end, int hotelId, RmsDbContext db)
        {
            return(await
                   Task.Run(() =>
            {
                HotelSettings hotel = db.HotelSettings.Find(hotelId);

                if (hotel == null || !hotel.IsRmsEnalbed)
                {
                    return null;
                }
                var calculations = new List <Calculation>();
                for (var s = start.Date; s <= end.Date; s = s.AddDays(1))
                {
                    calculations.Add(db.Calculations.Where(c => c.HotelId == hotelId && DbFunctions.TruncateTime(c.PredictionDate) == s).OrderByDescending(c => c.CalculatedOn).FirstOrDefault());
                }
                IEnumerable <Reservation> reservations = db.Reservations.Where(r => r.HotelId == hotelId && (r.CheckInDate <= end.Date && DbFunctions.AddDays(r.CheckInDate, r.DaysCount - 1) >= start.Date)).ToList();
                IEnumerable <Reservation> groupReservations = db.Reservations.Where(r => r.HotelId == hotelId && r.ReservationType == ReservationType.Group).ToList();
                var rmsAdapter = new RmsAdapter();
                rmsAdapter.RunGroupCalculation(start, end, reservations, groupReservations, calculations, hotel.Settings);
                return rmsAdapter;
            }));
        }
Example #18
0
 public RmsBaseController(RmsDbContext context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
 }
Example #19
0
 public MeasuresController(RmsDbContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Example #20
0
 public BaseInfoesController(RmsDbContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Example #21
0
 public UtilitiesController(RmsDbContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Example #22
0
 public MainController(RmsDbContext context) : base(context)
 {
 }
Example #23
0
 public CompaniesController(RmsDbContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Example #24
0
 public LogTypesController(RmsDbContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Example #25
0
 public BranchesController(RmsDbContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Example #26
0
 public ReplyRepository(RmsDbContext db) : base(db)
 {
     _db = db;
 }
Example #27
0
 public WarehousesController(RmsDbContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Example #28
0
 public StuffSuppliersController(RmsDbContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Example #29
0
 public PaymentGroupsController(RmsDbContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Example #30
0
 public DrawersController(RmsDbContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }