Ejemplo n.º 1
0
        public MenuOrder(Menu menu, DateTime date, IEnumerable<EmployeeMenu> employeeMenues)
        {
            Date = date.Date;
            Id = GenerateId(menu.Id, date);
            MenuId = menu.Id;

            DetailByUserName = new Dictionary<string, MenuOrderDetailItem>();
            PlacesByKey = menu.Places.ToDictionary(x => x.Key, x => x.Text);
            OptionsByKey = menu.Options.ToDictionary(x => x.Key, x => x.Text);

            var dayWeek = menu.GetWeekDay(Date);
            DayIdx = dayWeek.DayIdx;
            WeekIdx = dayWeek.WeekIdx;

            FoodsByOption = OptionsByKey
                .Select(x => menu.Foods.GetItemSecurely(new WeekDayOptionKey() { WeekIdx = WeekIdx, DayIdx = DayIdx, OptionKey = x.Key }))
                .Where(x => !string.IsNullOrWhiteSpace(x.Food))
                .ToDictionary(x => x.OptionKey, x => x.Food);

            employeeMenues = employeeMenues ?? Enumerable.Empty<EmployeeMenu>();

            foreach (var employeeMenu in employeeMenues)
            {
                DetailByUserName[employeeMenu.UserName] = CreateDetailItem(employeeMenu);
            }

            QuantityByOptionByPlace = DetailByUserName.Values
                .Where(x => IsNotEmpty(x.PlaceKey) && IsNotEmpty(x.OptionKey))
                .GroupBy(x => x.PlaceKey)
                .ToDictionary(
                    x => x.Key,
                    x => x.GroupBy(y => y.OptionKey).ToDictionary(y => y.Key, y => y.Count()));
        }
Ejemplo n.º 2
0
        public static EmployeeMenuDTO Create(Employee employee, Menu menuDefinition, EmployeeMenu employeeMenu, MenuOrder lastOrder)
        {
            employeeMenu.EmployeeName = string.Format("{0}, {1}", employee.LastName, employee.FirstName);

            var result = new EmployeeMenuDTO
            {
                EmployeeMenu = employeeMenu,
                MenuDefinition = menuDefinition
            };

            if (lastOrder != null && lastOrder.DetailByUserName.ContainsKey(employee.UserName))
            {
                var detail = lastOrder.DetailByUserName[employee.UserName];
                result.LastOrder = new EmployeeMenuOrderDTO()
                {
                    Date = menuDefinition.LastOrderDate,
                    Option = detail.OptionKey == null ? null : lastOrder.OptionsByKey[detail.OptionKey],
                    Place = detail.PlaceKey == null ? null : lastOrder.PlacesByKey[detail.PlaceKey],
                    Comment = detail.Comment,
                    Food = detail.OptionKey == null ? null : lastOrder.FoodsByOption[detail.OptionKey],
                    WeekIdx = lastOrder.WeekIdx,
                    DayIdx = lastOrder.DayIdx,
                    IsOrdered = true
                };
            }
            else if (lastOrder != null)
            {
                result.LastOrder = new EmployeeMenuOrderDTO()
                {
                    Date = menuDefinition.LastOrderDate,
                    Option = null,
                    Place = null,
                    Comment = "// El usuario no existía al momento de hacer el pedido //",
                    Food = null,
                    WeekIdx = lastOrder.WeekIdx,
                    DayIdx = lastOrder.DayIdx,
                    IsOrdered = true
                };
            }

            return result;
        }
Ejemplo n.º 3
0
 public JsonNetResult PostMenuDefinition(Menu menuDefinition)
 {
     ExecuteCommand(new UpdateMenuDefinitionCommand(menuDefinition, DateTime.Now));
     return Json(new { ok = true });
 }