Пример #1
0
        public ActionResult NewModificationLot(NewModificationLotModel model)
        {
            if (ModelState.IsValid)
            {
                using (var db = new BGS_DBContext()) {
                    string userIdentityId = User.Identity.GetUserId();
                    var    seller         = db.Users.Single(u => u.Id == userIdentityId);
                    for (int i = 0; i < model.LotCount; i++)
                    {
                        switch (model.Type)
                        {
                        case ModificationType.Aim:
                            AimModificationModel newAimModModel = new AimModificationModel()
                            {
                                Item = model.Item, WeaponType = model.WeaponType
                            };
                            db.AimModificationModels.Add(newAimModModel);
                            db.SaveChanges();
                            var aimLot = new LotModel()
                            {
                                Seller   = seller,
                                ItemId   = newAimModModel.Id,
                                Price    = model.Price,
                                SellerId = seller.GameId,
                                Status   = LotStatus.Available,
                                Type     = LotType.Modification
                            };
                            db.LotModels.Add(aimLot);
                            db.SaveChanges();
                            newAimModModel.LotId = aimLot.Id;
                            break;

                        case ModificationType.Magazine:
                            MagazineModificationModel newMagazineModModel = new MagazineModificationModel()
                            {
                                Item = model.Item, WeaponType = model.WeaponType
                            };
                            db.MagazineModificationModels.Add(newMagazineModModel);
                            db.SaveChanges();
                            var maganineLot = new LotModel()
                            {
                                Seller   = seller,
                                ItemId   = newMagazineModModel.Id,
                                Price    = model.Price,
                                SellerId = seller.GameId,
                                Status   = LotStatus.Available,
                                Type     = LotType.Modification
                            };
                            db.LotModels.Add(maganineLot);
                            db.SaveChanges();
                            newMagazineModModel.LotId = maganineLot.Id;
                            break;

                        case ModificationType.Barrel:
                            BarrelModificationModel newBarrelModModel = new BarrelModificationModel()
                            {
                                Item = model.Item, WeaponType = model.WeaponType
                            };
                            db.BarrelModificationModels.Add(newBarrelModModel);
                            db.SaveChanges();
                            var barrelLot = new LotModel()
                            {
                                Seller   = seller,
                                ItemId   = newBarrelModModel.Id,
                                Price    = model.Price,
                                SellerId = seller.GameId,
                                Status   = LotStatus.Available,
                                Type     = LotType.Modification
                            };
                            db.LotModels.Add(barrelLot);
                            db.SaveChanges();
                            newBarrelModModel.LotId = barrelLot.Id;
                            break;

                        case ModificationType.Butt:
                            ButtModificationModel newButtModModel = new ButtModificationModel()
                            {
                                Item = model.Item, WeaponType = model.WeaponType
                            };
                            db.ButtModificationModels.Add(newButtModModel);
                            db.SaveChanges();
                            var buttLot = new LotModel()
                            {
                                Seller   = seller,
                                ItemId   = newButtModModel.Id,
                                Price    = model.Price,
                                SellerId = seller.GameId,
                                Status   = LotStatus.Available,
                                Type     = LotType.Modification
                            };
                            db.LotModels.Add(buttLot);
                            db.SaveChanges();
                            newButtModModel.LotId = buttLot.Id;
                            break;
                        }
                    }
                    db.SaveChanges();
                    return(RedirectToAction("Index", "Market"));
                }
            }
            ModelState.AddModelError("", "Что то не правильно");
            return(View(model));
        }
Пример #2
0
        public ActionResult NewModificationLot()
        {
            var model = new NewModificationLotModel();

            return(View(model));
        }