Beispiel #1
0
        public static SetAsPrevDto GetSetAsPrevDtoById(this IRepositoryAsync <WeekOrderMenu> repository, int weekordid)
        {
            WeekOrderMenu curOrderMenu = repository.FindOrderMenuById(weekordid);
            WeekYearDto   curwyDto     = new WeekYearDto
            {
                Week = curOrderMenu.MenuForWeek.WorkingWeek.WeekNumber,
                Year = curOrderMenu.MenuForWeek.WorkingWeek.Year.YearNumber
            };
            WeekYearDto preWeekYearDto = YearWeekHelp.GetPrevWeekYear(curwyDto);

            WeekOrderMenu prevWeekOrder = repository.Query()
                                          .Include(om => om.User)
                                          .Include(om => om.MenuForWeek.WorkingWeek.Year)
                                          .Select().FirstOrDefault(om =>
                                                                   string.Equals(om.User.Id, curOrderMenu.User.Id) &&
                                                                   om.MenuForWeek.WorkingWeek.WeekNumber == preWeekYearDto.Week &&
                                                                   om.MenuForWeek.WorkingWeek.Year.YearNumber == preWeekYearDto.Year);

            if (prevWeekOrder != null)
            {
                return new SetAsPrevDto
                       {
                           PrevWeekOrdId = prevWeekOrder.Id,
                           DayNames      = repository.Context.GetDayNames(preWeekYearDto, true).Result,
                           Prevquants    = repository.Context.FactDishQuantByWeekOrderId(prevWeekOrder.Id).Result
                       }
            }
            ;
            return(null);
        }
        public async Task <IHttpActionResult> NextWeekOrderExists()
        {
            WeekYearDto curWeekYearDto  = YearWeekHelp.GetCurrentWeekYearDto();
            WeekYearDto nextWeekYearDto = YearWeekHelp.GetNextWeekYear(curWeekYearDto);

            string userid = RequestContext.Principal.Identity.GetUserId();

            WeekOrderMenu wom = _orderMenuService.FindByUserIdWeekYear(userid, nextWeekYearDto);

            return(Ok(wom != null));
        }
Beispiel #3
0
        public static void PrevOrdersMenuById(this IRepositoryAsync <WeekOrderMenu> repository, int weekordid)
        {
            WeekOrderMenu curOrderMenu = repository.FindOrderMenuById(weekordid);
            WeekYearDto   curwyDto     = new WeekYearDto
            {
                Week = curOrderMenu.MenuForWeek.WorkingWeek.WeekNumber,
                Year = curOrderMenu.MenuForWeek.WorkingWeek.Year.YearNumber
            };
            WeekYearDto preWeekYearDto = YearWeekHelp.GetPrevWeekYear(curwyDto);


            WeekOrderMenu prevWeekOrder = repository.Query()
                                          .Include(om => om.User)
                                          .Include(om => om.MenuForWeek.WorkingWeek.Year)
                                          .Include(wm => wm.MenuForWeek.WorkingWeek.WorkingDays.Select(d => d.DayOfWeek))
                                          .Include(om => om.DayOrderMenus.Select(dm => dm.MenuForDay.DishPriceMfdRelations.Select(dp => dp.Dish.DishType)))
                                          .Include(om => om.DayOrderMenus.Select(dm => dm.MenuForDay.DishPriceMfdRelations.Select(dp => dp.Dish.DishDetail)))
                                          .Include(om => om.DayOrderMenus.Select(dm => dm.MenuForDay.DishPriceMfdRelations.Select(dp => dp.DishPrice)))
                                          .Select().FirstOrDefault(om =>
                                                                   string.Equals(om.User.Id, curOrderMenu.User.Id) &&
                                                                   om.MenuForWeek.WorkingWeek.WeekNumber == preWeekYearDto.Week &&
                                                                   om.MenuForWeek.WorkingWeek.Year.YearNumber == preWeekYearDto.Year);

            if (prevWeekOrder == null)
            {
                return;
            }
            List <DayOrderMenu> curDayOrderMenus  = repository.DayOrdsByWeekOrdId(weekordid);
            List <DayOrderMenu> prevDayOrderMenus = repository.DayOrdsByWeekOrdId(prevWeekOrder.Id);

            curDayOrderMenus.ForEach(curdayord =>
            {
                if (curdayord.MenuForDay.WorkingDay.IsWorking && curdayord.MenuForDay.OrderCanBeChanged)
                {
                    DayOrderMenu prevDayOrd =
                        prevDayOrderMenus.FirstOrDefault(dord => dord.MenuForDay.WorkingDay.DayOfWeek.Id == curdayord.MenuForDay.WorkingDay.DayOfWeek.Id);
                    List <DishQuantityRelations> curdrels =
                        repository.GetRepositoryAsync <DishQuantityRelations>().GetRelationsListByDayOrdId(curdayord.Id);
                    List <DishQuantityRelations> prevdrels =
                        repository.GetRepositoryAsync <DishQuantityRelations>().GetRelationsListByDayOrdId(prevDayOrd.Id);
                    for (int i = 0; i < curdrels.Count; i++)
                    {
                        DishQuantityRelations rel = curdrels[i];
                        rel.DishQuantityId        = prevdrels.Count == 0
                          ? repository.GetRepositoryAsync <MfdDishPriceRelations>().GetDishPrice(0.00).Id
                          : prevdrels[i].DishQuantityId;
                        repository.Context.Entry(rel).State = EntityState.Modified;
                    }
                }
            });
        }
        public void TestDeleteWeekOrder()
        {
            User        user  = _userManager.FindByName("employee");
            WeekYearDto wyDto = new WeekYearDto
            {
                Week = 19,
                Year = 2016
            };
            WeekOrderMenu weekOrderMenu = _weekOrderMenuService.FindByUserIdWeekYear(user.Id, wyDto);

            _weekOrderMenuService.Delete(weekOrderMenu);
            weekOrderMenu = _weekOrderMenuService.FindByUserIdWeekYear(user.Id, wyDto);
            Assert.IsNull(weekOrderMenu);
        }
 /// <param name="context"></param>
 /// <param name="weekOrderMenu"></param>
 /// <returns></returns>
 public static UserWeekOrderDto MapDto(ApplicationDbContext context, WeekOrderMenu weekOrderMenu)
 {
     return(new UserWeekOrderDto
     {
         UserId = weekOrderMenu.User.Id,
         UserName = string.Format("{0} {1}", weekOrderMenu.User.LastName, weekOrderMenu.User.FirstName),
         OrderId = weekOrderMenu.Id,
         DayOrdIdArray =
             weekOrderMenu.DayOrderMenus.Where(dord => dord.MenuForDay.WorkingDay.IsWorking)
             .Select(dord => dord.Id)
             .ToArray(),
         UserWeekOrderDishes = context.FactDishQuantByWeekOrderId(weekOrderMenu.Id).Result
     });
 }
        public static void CreateOrders(ApplicationDbContext context)
        {
            var                         roleManager       = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            IdentityRole                role              = roleManager.FindByName("Employee");
            List <User>                 users             = context.Users.Where(u => u.Roles.Select(r => r.RoleId).Contains(role.Id)).ToList();
            List <MenuForWeek>          weekmenus         = context.MenuForWeeks.ToList();
            List <DishQuantity>         dquaQuantities    = context.DishQuantities.ToList();
            List <WeekOrderMenu>        weekOrders        = new List <WeekOrderMenu>();
            List <PlannedWeekOrderMenu> plannedWeekOrders = new List <PlannedWeekOrderMenu>();
            int                         rnd;

            double[][] coursesnums =
            {
                new[] { 0, 0.5, 0.5, 1.0, 1.0, 1.0, 1.0, 1.5 },
                new[] { 0,   0, 1.0, 1.0, 1.0, 1.0,2.0 },
                new[] { 0,1.0 },
                new[] { 0, 1.0 }
            };
            int[] numsForCourses = new int[4];

            for (int i = 0; i < 4; i++)
            {
                numsForCourses[i] = coursesnums[i].Length;
            }
            List <DishQuantityRelations>     dquaList     = new List <DishQuantityRelations>();
            List <PlanDishQuantityRelations> plandquaList = new List <PlanDishQuantityRelations>();

            foreach (User user in users)
            {
                foreach (MenuForWeek mfw in weekmenus)
                {
                    WeekOrderMenu weekOrder = new WeekOrderMenu
                    {
                        User                  = user,
                        MenuForWeek           = mfw,
                        WeekOrderSummaryPrice = 0.0
                    };
                    PlannedWeekOrderMenu plannedWeekOrderMenu = new PlannedWeekOrderMenu
                    {
                        User                  = user,
                        MenuForWeek           = mfw,
                        WeekOrderSummaryPrice = 0.0
                    };

                    List <DayOrderMenu>        dayOrderMenus     = new List <DayOrderMenu>();
                    List <PlannedDayOrderMenu> plandayOrderMenus = new List <PlannedDayOrderMenu>();

                    List <DishType> dishTypes = context.DishTypes.ToList();
                    foreach (MenuForDay daymenu in mfw.MenuForDay)
                    {
                        DayOrderMenu dayOrderMenu = new DayOrderMenu
                        {
                            MenuForDay = daymenu,
                        };
                        PlannedDayOrderMenu plannedDayOrderMenu = new PlannedDayOrderMenu
                        {
                            MenuForDay = daymenu
                        };
                        foreach (MfdDishPriceRelations mdrs in context.MfdDishPriceRelations.Include("DishPrice").Include("Dish.DishType").Where(mdpr => mdpr.MenuForDayId == daymenu.ID).ToList())
                        {
                            DishType first = dishTypes.FirstOrDefault(dy => dy.Id == mdrs.Dish.DishType.Id);
                            if (first != null)
                            {
                                int catindex = first.Id - 1;

                                rnd = Rand.Next(numsForCourses[catindex]);
                                DishQuantity dqu = dquaQuantities.FirstOrDefault(
                                    dq => dq.Quantity == coursesnums[catindex][rnd]);
                                DishQuantityRelations dqrs = new DishQuantityRelations
                                {
                                    DishQuantity = dqu,
                                    DishType     = first,
                                    DayOrderMenu = dayOrderMenu
                                };
                                PlanDishQuantityRelations plandqrs = new PlanDishQuantityRelations
                                {
                                    DishQuantity        = dqu,
                                    DishType            = first,
                                    PlannedDayOrderMenu = plannedDayOrderMenu
                                };
                                if (dqu != null)
                                {
                                    dayOrderMenu.DayOrderSummaryPrice += dqu.Quantity * mdrs.DishPrice.Price;
                                }
                                dquaList.Add(dqrs);
                                plandquaList.Add(plandqrs);
                            }
                        }
                        //dayOrderMenu.DayOrderSummaryPrice=
                        plannedDayOrderMenu.DayOrderSummaryPrice = dayOrderMenu.DayOrderSummaryPrice;
                        dayOrderMenus.Add(dayOrderMenu);
                        plandayOrderMenus.Add(plannedDayOrderMenu);
                    }
                    weekOrder.DayOrderMenus = dayOrderMenus;
                    plannedWeekOrderMenu.PlannedDayOrderMenus = plandayOrderMenus;
                    weekOrder.WeekOrderSummaryPrice           =
                        weekOrder.DayOrderMenus.Where(dom => dom.MenuForDay.WorkingDay.IsWorking)
                        .Sum(dom => dom.DayOrderSummaryPrice);

                    plannedWeekOrderMenu.WeekOrderSummaryPrice = weekOrder.WeekOrderSummaryPrice;

                    weekOrders.Add(weekOrder);
                    plannedWeekOrders.Add(plannedWeekOrderMenu);
                }
            }
            List <WeekPaiment> weekPaiments = new List <WeekPaiment>();

            weekOrders.ForEach(x =>
            {
                weekPaiments.Add(new WeekPaiment
                {
                    Paiment       = x.WeekOrderSummaryPrice,
                    WeekIsPaid    = true,
                    WeekOrderMenu = x
                });
            });
            context.WeekPaiments.AddRange(weekPaiments);
            context.WeekOrderMenus.AddRange(weekOrders);
            context.PlannedWeekOrderMenus.AddRange(plannedWeekOrders);
            context.DQRelations.AddRange(dquaList);
            context.PlanDQRelations.AddRange(plandquaList);
            context.SaveChanges();
        }