Пример #1
0
        public ActionResult Create(CreateStockModel input)
        {
            var item = _itemRepo.Find(input.ItemId);

            if (item == null)
            {
                return(HttpNotFound("Cannot find item with specified itemId"));
            }

            if (ModelState.IsValid)
            {
                _itemRepo.AddStocks(item.Id, CreateStockModel.Explode(input));

                LogActivity(string.Format("added {0} stock items to ", input.Quantity),
                            TimelineActivityObjectType.Item, item.Name, item.Id);

                FlashSuccess(string.Format("added {0} stock items to {1}", input.Quantity, item.Name));

                return(RedirectToAction("Details", "Items", new { id = input.ItemId }));
            }

            ViewBag.StockConditionId = new SelectList(Db.StockConditions, "Id", "Name", input.StockConditionId);

            input = new CreateStockModel {
                ItemId = input.ItemId, Item = item
            };

            return(View(input));
        }
Пример #2
0
        protected override void Seed(DialogueStoreContext context)
        {
            var user = new User
            {
                LastLogin    = DateTime.UtcNow,
                Locked       = false,
                Approved     = true,
                Role         = Role.Admin.ToString(),
                DisplayName  = "Administrator",
                Email        = "*****@*****.**",
                Password     = "******",
                Phone        = "08093188347",
                SecretAnswer = "What is Dialogue?"
            };

            user.SecretAnswer = "Dialogue";
            user.UserName     = "******";
            context.Users.Add(user);
            context.SaveChanges();

            var stockConditionRepo = new StockConditionRepository(context);
            var stockConditions    = CreateStockConditions().ToList();

            stockConditions.ForEach(stockCondition => stockConditionRepo.Add(stockCondition));

            var locationRepo = new LocationRepository(context);
            var locations    = CreateLocations().ToList();

            locations.ForEach(location => locationRepo.Add(location));

            var itemRepo = new ItemRepository(context);
            var items    = CreateItems(stockConditions).ToList();

            items.ForEach(item => itemRepo.Add(item));

            var random = new Random();

            // Add stock
            foreach (var item in items)
            {
                var stocks  = new List <Stock>();
                var batchId = Guid.NewGuid();

                for (var i = 0; i < random.Next(1, 5); i++)
                {
                    stocks.Add(new Stock
                    {
                        BatchId          = batchId,
                        BatchPrice       = random.Next(10, 2000),
                        UnitPrice        = random.Next(10, 2000),
                        ItemId           = item.Id,
                        StockConditionId = stockConditions[random.Next(0, stockConditions.Count - 1)].Id
                    });
                }

                itemRepo.AddStocks(item.Id, stocks);
            }

            context.SaveChanges();
            base.Seed(context);
        }