示例#1
0
        public string OrderDelivered(Guid guid)
        {
            using (var context = new MainDatabaseContext())
            {
                var order = context.Orders
                            .Where(x => x.Id == guid)
                            .Include(x => x.Buyer)
                            .FirstOrDefault();

                if (order == null)
                {
                    return("order not found");
                }
                if (order.Status != OrderStatus.Delivering)
                {
                    return("invalid order status");
                }

                order.Delivered();

                _emailService.SendEmail(order.Buyer.Email, EmailType.OrderReceived);

                context.SaveChanges();
            }

            return("order delivered");
        }
示例#2
0
        public Report GenerateReport()
        {
            var report = new Report();

            using (var ctx = new MainDatabaseContext())
            {
                var orders = ctx.Orders
                             .Include(x => x.Buyer)
                             .Include(x => x.Payment)
                             .Include(x => x.ProductOrders.Select(po => po.Product))
                             .ToList();

                var pendingOrders = orders.Count(x => x.Status == OrderStatus.Delivering);
                report.PendingOrders = pendingOrders;

                var deliveredOrders = orders.Count(x => x.Status == OrderStatus.Finished);
                report.DeliveredOrders = deliveredOrders;

                var moneySold = orders.Sum(x => x.Price);
                report.MoneySold = moneySold;

                var numberSold = orders.Sum(x => x.ProductOrders.Sum(po => po.Count));
                report.NumberSold = numberSold;
            }

            //Magic :D
            Thread.Sleep(4000);

            return(report);
        }
        public async Task <List <Guid> > OrderByLongestImpression(
            IEnumerable <Guid> cards,
            int historyDepth,
            CardSide side)
        {
            using (var context = new MainDatabaseContext())
            {
                var accountedForImpressions = await context.CardImpressions
                                              .Where(x => cards.Any(y => y == x.CardId))
                                              .Where(x => x.TestedSide == side)
                                              .GroupBy(x => x.CardId)
                                              .ToDictionaryAsync(
                    x => x.Key,
                    x => x.OrderByDescending(y => y.Date).Take(historyDepth));

                var impressionsOrderedBySpentMedian = accountedForImpressions
                                                      .OrderByDescending(x => x.Value.Select(y => side == CardSide.Front
                        ? y.FrontMillisecondsSpent
                        : y.BackMillisecondsSpent)
                                                                         .Median())
                                                      .Select(x => x.Key);

                var newCards = cards.Except(impressionsOrderedBySpentMedian);
                return(newCards.Union(impressionsOrderedBySpentMedian).ToList());
            }
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e != null)
            {
                if (e.Parameter as Project != null)
                {
                    Project proj = (Project)e.Parameter;

                    ScheduleViewModel = new ScheduleViewModel(proj);
                    ViewModel         = new PersonalEventCreateViewModel();

                    ViewModel.CurrentMapEvent.ProjectId = proj.Id;
                    ViewModel.CurrentMapEvent.Color     = proj.Color;
                }

                if (e.Parameter as MapEvent != null)
                {
                    MapEvent mapEvent = (MapEvent)e.Parameter;
                    using (MainDatabaseContext db = new MainDatabaseContext())
                    {
                        var proj = db.Projects.FirstOrDefault(i => i.Id == mapEvent.ProjectId);
                        ScheduleViewModel = new ScheduleViewModel(proj);
                    }

                    ViewModel = new PersonalEventCreateViewModel(mapEvent);
                }
            }
        }
        private void AddAppUsers(MainDatabaseContext context)
        {
            SystemUser sysAdmin = context.SystemUsers.Where(x => x.Name == SystemUsers.SystemUserName).FirstOrDefault();

            if (!context.AppUsers.Any())
            {
                Language polish       = context.Languages.FirstOrDefault(x => x.LanguageDictionary == LanguageDictionary.Polish);
                AppRole  adminRole    = context.AppRoles.FirstOrDefault(x => x.AppRoleType == AppRoleType.Administrator);
                string   currentlogin = $"{Environment.MachineName}\\{Environment.UserName}";

                var admin = new AppUser()
                {
                    CreatedById = sysAdmin.Id,
                    CreatedDate = DateTime.Now,
                    Email       = "*****@*****.**",
                    IsActive    = true,
                    LastName    = "Administrator",
                    FirstName   = "",
                    LanguageId  = polish.Id,
                    Login       = currentlogin
                };
                context.AppUsers.Add(admin);

                var adminAdmin = new AppUserRole()
                {
                    CreatedById = sysAdmin.Id,
                    CreatedDate = DateTime.Now,
                    AppRole     = adminRole,
                    AppUser     = admin
                };
                context.AppUserRoles.Add(adminAdmin);

                context.SaveChanges();
            }
        }
示例#6
0
 public IActionResult Index()
 {
     using (var context = new MainDatabaseContext())
     {
         var products = context.Products.ToList();
         return(View(products));
     }
 }
 protected override void Seed(MainDatabaseContext context)
 {
     AddCoreData(context);
     AddAppSeetings(context);
     AddFunctionalities(context);
     AddAppRoles(context);
     AddAppUsers(context);
 }
        public async Task AddImpression(CardImpression impression)
        {
            using (var context = new MainDatabaseContext())
            {
                await context.CardImpressions.AddAsync(impression);

                await context.SaveChangesAsync();
            }
        }
 public async Task <IEnumerable <CardImpression> > GetImpressions(IEnumerable <Guid> cardIds)
 {
     using (var context = new MainDatabaseContext())
     {
         return(await context.CardImpressions
                .Where(x => cardIds.Any(y => y == x.CardId))
                .AsNoTracking()
                .ToListAsync());
     }
 }
示例#10
0
 public IActionResult Index()
 {
     using (var context = new MainDatabaseContext())
     {
         var products = context.ProductsWarehouse
                        .Include(c => c.Product)
                        .ToList();
         return(View(products));
     }
 }
示例#11
0
        protected TestWithSqlite()
        {
            _connection = new SqliteConnection(InMemoryConnectionString);
            _connection.Open();
            var options = new DbContextOptionsBuilder <MainDatabaseContext>()
                          .UseSqlite(_connection)
                          .Options;

            DbContext = new MainDatabaseContext(options);
            DbContext.Database.EnsureCreated();
        }
 private void AddAppSeetings(MainDatabaseContext context)
 {
     if (!context.AppSettings.Any(r => r.Type == AppSettingEnum.ApplicationWebAddress))
     {
         AppSetting setting = new AppSetting();
         setting.Type  = AppSettingEnum.ApplicationWebAddress;
         setting.Value = "http://localhost:18828/";
         context.AppSettings.Add(setting);
     }
     context.SaveChanges();
 }
        protected void Application_Start()
        {
            DevExtremeBundleConfig.RegisterBundles(BundleTable.Bundles);

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
#if !DEBUG
            MainDatabaseContext.MigrateData();
#endif
        }
示例#14
0
        public App()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;

            using (var db = new MainDatabaseContext())
            {
                db.Database.Migrate();
            }

            HockeyClient.Current.Configure("c72c77abf0814629a4e5bb469d91a1ae");
        }
        public IActionResult Index(Guid orderId)
        {
            using (var context = new MainDatabaseContext())
            {
                var order = context.Orders
                            .Where(x => x.Id == orderId)
                            .Include(p => p.ProductOrders.Select(po => po.Product))
                            .FirstOrDefault();

                return(View(order));
            }
        }
示例#16
0
        public IActionResult Put([FromBody] ICollection <ProductOrder> productOrders)
        {
            var order = new Order(productOrders);

            using (var context = new MainDatabaseContext())
            {
                context.Orders.Add(order);
                context.SaveChanges();
            }

            return(Ok(new { orderId = order.Id }));
        }
示例#17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AccessHandlerManager"/> class
        /// </summary>
        /// <param name="context">The <see cref="MainDatabaseContext"/> instance to use</param>
        /// <param name="creatingAuditLogs">The CreatingAuditLogs event handler used to fill in any missing details. CURRENTLY NOT USED!!!</param>
        internal AccessHandlerManager(MainDatabaseContext context, CreatingAuditLogsEventHandler creatingAuditLogs = null)
        {
            //// if(creatingAuditLogs != null) context.CreatingAuditLogs += creatingAuditLogs;

            this.questionnaireAccessHandler       = new QuestionnaireAccessHandler(context);
            this.questionnaireFormatAccessHandler = new QuestionnaireFormatAccessHandler(context);
            this.tagAccessHandler     = new TagAccessHandler(context);
            this.userAccessHandler    = new UserAccessHandler(context);
            this.messageHandler       = new MessageHandler(context);
            this.episodeAccessHandler = new EpisodeAccessHandler(context);
            this.notificationHandler  = new NotificationHandler(context);
            this.auditHandler         = new AuditHandler(context);
            this.searchHandler        = new SearchHandler(context);
        }
示例#18
0
        public IActionResult Update([FromForm] int numberAvailable, int id)
        {
            using (var context = new MainDatabaseContext())
            {
                var productWarehouse = context.ProductsWarehouse
                                       .SingleOrDefault(x => x.Product.Id == id);

                productWarehouse.NumberAvailable = numberAvailable;

                context.SaveChanges();

                return(RedirectToAction("Index"));
            }
        }
        private void AddFunctionalities(MainDatabaseContext context)
        {
            if (!context.Functionalities.Any(x => x.FunctionalityType == FunctionalityType.GeneralSettings))
            {
                var functionality = new Functionality()
                {
                    FunctionalityType = FunctionalityType.GeneralSettings,
                    Name        = "Name",
                    Description = "Description",
                };
                context.Functionalities.Add(functionality);
            }

            context.SaveChanges();
        }
示例#20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SecuritySessionStorage"/> class
        /// </summary>
        public SecuritySessionStorage()
        {
            using (MainDatabaseContext context = new MainDatabaseContext())
            {
                this.internalStore = new ConcurrentDictionary <string, SessionDetails>(context.SessionStore.ToDictionary(s => s.SessionId, s => s));
            }

            this.databaseUpdater = new TaskFactory().StartNew(this.UpdateDatabase);

            this.houseKeeper           = new System.Timers.Timer();
            this.houseKeeper.Interval  = 60000; // 1 minute
            this.houseKeeper.AutoReset = true;
            this.houseKeeper.Elapsed  += this.HouseKeeper_Elapsed;
            this.houseKeeper.Start();
        }
        public IActionResult Index()
        {
            using (var context = new MainDatabaseContext())
            {
                var email = User.GetEmail();

                var orders = context.Orders
                             .Where(x => x.Buyer.Email == email)
                             .Include(x => x.Buyer)
                             .Include(x => x.Payment)
                             .Include(x => x.ProductOrders.Select(po => po.Product))
                             .ToList();

                return(View(orders));
            }
        }
        public async Task <List <Guid> > OrderByLongestUnseen(IEnumerable <Guid> cards)
        {
            using (var context = new MainDatabaseContext())
            {
                var set = context.CardImpressions;
                var orderedImpressions = await set
                                         .Where(x => cards.Any(y => y == x.CardId))
                                         .GroupBy(x => x.CardId)
                                         .OrderBy(x => x.Max(y => y.Date))
                                         .Select(x => x.Key)
                                         .ToListAsync();

                var newCards = cards.Except(orderedImpressions);
                return(newCards.Union(orderedImpressions).ToList());
            }
        }
        private void AddCoreData(MainDatabaseContext context)
        {
            if (!context.Languages.Any())
            {
                Language polish = new Language()
                {
                    CultureSymbol      = "pl-PL",
                    LanguageDictionary = LanguageDictionary.Polish
                };
                context.Languages.Add(polish);
                context.SaveChanges();
            }
            if (!context.SystemUsers.Any())
            {
                Language   polish = context.Languages.FirstOrDefault(x => x.LanguageDictionary == LanguageDictionary.Polish);
                SystemUser admin  = new SystemUser()
                {
                    CreatedDate = DateTime.Now,
                    Email       = SystemUsers.SystemUserEmail,
                    FirstName   = SystemUsers.SystemUserName,
                    IsActive    = true,
                    LastName    = "",
                    LanguageId  = polish.Id,
                    Name        = SystemUsers.SystemUserName
                };
                context.SystemUsers.Add(admin);
                context.SaveChanges();
                admin.CreatedById          = admin.Id;
                context.Entry(admin).State = EntityState.Modified;

                SystemUser unknownUser = new SystemUser()
                {
                    CreatedDate = DateTime.Now,
                    CreatedById = admin.Id,
                    Email       = SystemUsers.UnknownUserEmail,
                    FirstName   = SystemUsers.UnknownUserName,
                    IsActive    = true,
                    LastName    = "",
                    LanguageId  = polish.Id,
                    Name        = SystemUsers.UnknownUserName
                };
                context.SystemUsers.Add(unknownUser);

                context.SaveChanges();
            }
        }
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (value is string projectId)
            {
                using (var db = new MainDatabaseContext())
                {
                    var project = db.Projects.FirstOrDefault(i => i.Id == projectId);
                    if (project != null)
                    {
                        return(project.Name);
                    }
                }
            }

            ResourceLoader resourceLoader = ResourceLoader.GetForCurrentView("FromGUIDToContactEmailConverter");

            return(resourceLoader.GetString("Undefined"));
        }
        private void AddAppRoles(MainDatabaseContext context)
        {
            SystemUser sysAdmin = context.SystemUsers.Where(x => x.Name == SystemUsers.SystemUserName).FirstOrDefault();

            if (!context.AppRoles.Any())
            {
                AppRole administrators = new AppRole()
                {
                    AppRoleType = AppRoleType.Administrator,
                    CreatedById = sysAdmin.Id,
                    CreatedDate = DateTime.Now,
                    Name        = "Administratorzy",
                    Description = "Grupa administratorów systemu",
                };
                context.AppRoles.Add(administrators);

                context.SaveChanges();
            }
        }
示例#26
0
        static void Main(string[] args)
        {
            MainDatabaseContext mainDatabase  = new MainDatabaseContext();
            shwaContext         worldDatabase = new shwaContext();

            var mapperConfiguration = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <Country, Fridge.Models.Main.Country>();
                cfg.CreateMap <City, Fridge.Models.Main.City>();
            });

            var mapper    = new Mapper(mapperConfiguration);
            var countries =
                mapper.Map <List <Country>, List <Fridge.Models.Main.Country> >(worldDatabase.Countries.Include(c => c.Cities)
                                                                                .ToList());

            mainDatabase.Countries.AddRange(countries);
            mainDatabase.SaveChanges();
        }
示例#27
0
        public string Init()
        {
            var mockedListOfProducts = new List <Product>
            {
                new Product(10.0m, "Bike", 1),
                new Product(5.0m, "Scooter", 2),
                new Product(4.99m, "Ball", 3),
                new Product(89.99m, "Helmet", 4)
            };

            var mockedListOfWarehouse = new List <ProductWarehouse>
            {
                new ProductWarehouse(mockedListOfProducts[0], 10),
                new ProductWarehouse(mockedListOfProducts[1], 10),
                new ProductWarehouse(mockedListOfProducts[2], 10),
                new ProductWarehouse(mockedListOfProducts[3], 10)
            };

            try
            {
                using (var context = new MainDatabaseContext())
                {
                    foreach (var mockedListOfProduct in mockedListOfProducts)
                    {
                        context.Products.Add(mockedListOfProduct);
                    }

                    foreach (var mockedWar in mockedListOfWarehouse)
                    {
                        context.ProductsWarehouse.Add(mockedWar);
                    }

                    context.SaveChanges();

                    return("data initialized");
                }
            }
            catch (Exception ex)
            {
                return($"there was a problem with \r\n- {ex.Message}");
            }
        }
示例#28
0
        public void Execute(IJobExecutionContext jobContext)
        {
            using (var context = new MainDatabaseContext())
            {
                var orders = context.Orders
                             .Where(x => x.Status == OrderStatus.WaitingForWarehouse)
                             .Include(o => o.Buyer)
                             .Include(o => o.ProductOrders.Select(p => p.Product))
                             .ToList();

                foreach (var order in orders)
                {
                    var cannotFulfill = (from productOrder in order.ProductOrders
                                         let productWarehouse = context.ProductsWarehouse.FirstOrDefault(pw => pw.Product.Id == productOrder.ProductId)
                                                                where productWarehouse.NumberAvailable < productOrder.Count
                                                                select productOrder).Any();

                    if (cannotFulfill)
                    {
                        break;
                    }
                    else
                    {
                        foreach (var productOrder in order.ProductOrders)
                        {
                            var productW = context.ProductsWarehouse
                                           .Include(pw => pw.Product)
                                           .FirstOrDefault(x => x.Product.Id == productOrder.ProductId);

                            productW.NumberAvailable = productW.NumberAvailable - productOrder.Count;
                        }

                        _emailService.SendEmail(order.Buyer.Email, EmailType.OrderSend);
                        order.Delivering();
                    }
                }

                context.SaveChanges();
            }
        }
        public void Execute(IJobExecutionContext jobContext)
        {
            using (var context = new MainDatabaseContext())
            {
                var orders = context.Orders
                             .Where(x => x.Status == OrderStatus.WaitingForPayment)
                             .Include(o => o.Buyer)
                             .ToList();

                foreach (var order in orders)
                {
                    var hasReceivedMoney = _transferCheckService.Check(order.Id);
                    if (hasReceivedMoney)
                    {
                        order.TransferReceived();
                        _emailService.SendEmail(order.Buyer.Email, EmailType.TransferReceived);
                    }
                }

                context.SaveChanges();
            }
        }
示例#30
0
        public IActionResult CreatePayment(Payment payment)
        {
            var email = User.GetEmail();

            var successfullPayment = false;

            using (var context = new MainDatabaseContext())
            {
                var order = context.Orders
                            .Where(x => x.Id == payment.OrderId)
                            .Include(p => p.ProductOrders.Select(po => po.Product))
                            .Include(p => p.Buyer)
                            .FirstOrDefault();

                if (order == null)
                {
                    return(View("Error"));
                }

                order.AddBuyer(GetOrCreateNewBuyer(context, email));

                if (payment.Type == PaymentType.Card)
                {
                    successfullPayment = _paymentProvider.SendPaymentData(payment);
                    order.PayByCard(payment, successfullPayment);
                    _emailService.SendEmail(email, successfullPayment ? EmailType.PaymentAccepted : EmailType.PaymentRefused);
                    context.SaveChanges();
                    return(successfullPayment ? View("Success") : View("Failure"));
                }
                else
                {
                    _emailService.SendEmail(email, EmailType.WaitingForTransfer);
                    order.PayByTransfer(payment);
                    context.SaveChanges();
                    return(View("Success"));
                }
            }
        }