public override void Up()
        {
            var filePath = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(new Uri(GetType().Assembly.CodeBase).LocalPath)), "Import201212010811.json");
            var serializer = new Newtonsoft.Json.JsonSerializer();
            var placeByUserName = serializer.Deserialize <Dictionary<string, string>>(new StreamReader(filePath));
            using (var session = DocumentStore.OpenSession())
            {
                var empty = false;
                var skip = 0;
                var take = 20;
                while (!empty) {
                    var result = session.Query<Employee>()
                        .Where(x => x.UserName != null && x.UserName != "")
                        .OrderBy(x => x.UserName)
                        .Skip(skip)
                        .Take(take)
                        .ToArray();

                    foreach (var employee in result)
                    {
                        string placeKey = null;
                        bool createMenu = false;
                        if (!string.IsNullOrWhiteSpace(employee.UserName) && placeByUserName.TryGetValue(employee.UserName, out placeKey) && placeKey != "-")
                        {
                            createMenu = true;
                        }
                        else if (!string.IsNullOrWhiteSpace(employee.UserName) && !placeByUserName.ContainsKey(employee.UserName))
                        {
                            if (!string.IsNullOrWhiteSpace(employee.Platform) && (employee.Platform.ToUpper().Contains("MDQ") || employee.Platform.ToUpper().Contains("MDP")  || employee.Platform.ToUpper().Contains("MAR")))
                            {
                                createMenu = true;
                                placeKey = employee.Platform.ToUpper().Contains("GARAY") ? "place_garay"
                                    : employee.Platform.ToUpper().Contains("RIOJA") ? "place_larioja"
                                    : null;
                            }
                        }

                        if (createMenu)
                        {
                            var employeeMenu = new EmployeeMenu()
                            {
                                Id = "Menu/" + employee.UserName,
                                MenuId = "Menu/DefaultMenu",
                                UserName = employee.UserName,
                                EmployeeName = string.Format("{0}, {1}", employee.LastName, employee.FirstName),
                                DefaultPlaceKey = placeKey,
                                WeeklyChoices = new WeekDayKeyedCollection<EmployeeMenuItem>(),
                                Overrides = new List<EmployeeMenuOverrideItem>()
                            };
                            session.Store(employeeMenu);
                        }
                    }

                    empty = result.Length == 0;
                    skip += take;
                }
                session.SaveChanges();
            }
        }
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;
        }
 public UpdateEmployeeMenuCommand(EmployeeMenu employeeMenu)
 {
     EmployeeMenu = employeeMenu;
 }
Ejemplo n.º 4
0
        private MenuOrderDetailItem CreateDetailItem(EmployeeMenu employeeMenu)
        {
            string defaultPlaceKey = null;
            string placeKey = null;
            string optionKey = null;

            defaultPlaceKey = placeKey = GetPlaceOrDefault(employeeMenu.DefaultPlaceKey, placeKey);

            var dayChoices = employeeMenu.WeeklyChoices.GetItemSecurely(new WeekDayKey() { WeekIdx = WeekIdx, DayIdx = DayIdx });

            placeKey = GetPlaceOrDefault(dayChoices.PlaceKey, placeKey);
            optionKey = GetOptionOrDefault(dayChoices.OptionKey, optionKey);

            var lastOverride = employeeMenu.Overrides.EmptyIfNull().Where(x => x.Date.Date == Date).LastOrDefault();

            if (!lastOverride.Cancel)
            {
                placeKey = GetPlaceOrDefault(lastOverride.PlaceKey, placeKey);
                optionKey = GetOptionOrDefault(lastOverride.OptionKey, optionKey);
            }

            if (lastOverride.Cancel || string.IsNullOrWhiteSpace(placeKey) || string.IsNullOrWhiteSpace(optionKey))
            {
                placeKey = null;
                optionKey = null;
            }

            var comment = IsNotEmpty(lastOverride.Comment) ? lastOverride.Comment : null;

            return new MenuOrderDetailItem()
            {
                EmployeeName = employeeMenu.EmployeeName,
                PlaceKey = placeKey ?? defaultPlaceKey,
                OptionKey = optionKey,
                Comment = comment
            };
        }
Ejemplo n.º 5
0
 public JsonNetResult PostOwnMenu(EmployeeMenu employeeMenu)
 {
     return PostEmployeeMenu(DetectUser(), employeeMenu);
 }
Ejemplo n.º 6
0
        public JsonNetResult PostEmployeeMenu(string id /*username*/, EmployeeMenu employeeMenu)
        {
            if (string.IsNullOrWhiteSpace(id) || employeeMenu.UserName != id)
                throw new ArgumentException(string.Format("No se permite modificar el menú del usuario o los ids no coinciden ({0}, {1})", id, employeeMenu.UserName));

            ExecuteCommand(new UpdateEmployeeMenuCommand(employeeMenu));

            return Json(new { ok = true });
        }