public async Task <ActionResult> Create([Bind(Include = "Id,Name,Price")] Accessories accessories)
        {
            if (ModelState.IsValid)
            {
                accessories.Status = 1;
                db.Accessories.Add(accessories);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(accessories));
        }
예제 #2
0
        public async Task <ActionResult> Create(string Username, string Password, string Passport, string City,
                                                string Home, string Apartament, string Surname, string Name, string Street,
                                                string Patronymic, string Phone)
        {
            User user = new User();

            if (ModelState.IsValid)
            {
                user = new User()
                {
                    Username = Username,
                    Password = Password
                };
                var         userInitialsName       = (Name != null && Name.Length > 0) ? Name[0] + "." : " ";
                var         userInitialsPatronymic = (Patronymic != null && Patronymic.Length > 0) ? Patronymic[0] + "." : "";
                СontactUser contactUser            = new СontactUser()
                {
                    Passport   = Passport,
                    City       = City,
                    Home       = Home,
                    Apartment  = Apartament,
                    Surname    = Surname,
                    Name       = Name,
                    Patronymic = Patronymic,
                    Phone      = Phone,
                    Street     = Street,
                    ShortName  = $"{Surname} {userInitialsName}  {userInitialsPatronymic}"
                };
                db.ContactUser.Add(contactUser);
                await db.SaveChangesAsync();

                //Добавляем созданные данные пользователя к авторизационным данным
                user.ContactUser = contactUser;
                //У полученные данных пользователя и сохраненных в БД берем ID (которые сгенерирован автоматически) и присваиваем в модель пользователя
                //user.ContactUserId = contactUser.Id;

                db.Users.Add(user);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            //ViewBag.ContactUserId = new SelectList(db.ContactUser, "Id", "ShortName", user.ContactUserId);
            return(View(user));
        }
        public async Task <ActionResult> Create(FormCollection collection)
        {
            Transport transport = new Transport();

            if (ModelState.IsValid)
            {
                if (int.TryParse(collection["TransportSelect2"].ToString(), out int idModel))
                {
                    transport.TransportModels = db.TransportModels.Find(idModel);
                }
                transport.SerialNumber = collection["SerialNumber"];
                transport.IndexNumber  = collection["IndexNumber"];
                transport.IsBlocked    = false;
                transport.Status       = 1;
                db.Transport.Add(transport);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(transport));
        }
예제 #4
0
        public async Task <ActionResult> Create(FormCollection collection)
        {
            if (ModelState.IsValid)
            {
                Rates rates = new Rates()
                {
                    Name        = collection["Name"],
                    Description = collection["Description"]
                };
                if (int.TryParse(collection["Duration"], out int duration))
                {
                    rates.Duration = duration;
                }

                db.Rates.Add(rates);

                var models = collection["Model"].Split(',');
                var prices = collection["Price"].Split(',');
                for (int i = 0, countModels = models.Count(); i < countModels; ++i)
                {
                    if (int.TryParse(models[i], out int numberModel))
                    {
                        RatesTransports ratesTransports = new RatesTransports()
                        {
                            TransportModels = db.TransportModels.Find(numberModel),
                            Rates           = rates
                        };
                        if (decimal.TryParse(prices[i], out decimal price))
                        {
                            ratesTransports.Price = price;
                        }
                        db.RatesTransports.Add(ratesTransports);
                    }
                }
            }
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }