Пример #1
0
        public async Task <IActionResult> Create(CarMarkViewModel model)
        {
            if (ModelState.IsValid & CheckUniqueValues(model.Entity))
            {
                await db.CarMarks.AddAsync(model.Entity);

                await db.SaveChangesAsync();

                cache.Clean();

                return(RedirectToAction("Index", "CarMarks"));
            }

            return(View(model));
        }
Пример #2
0
        public async Task <IActionResult> Create(CarModelViewModel model)
        {
            model.SelectList = db.CarMarks.ToList();
            var carMark = db.CarMarks.FirstOrDefault(g => g.Name == model.CarMarkName);

            if (carMark == null)
            {
                ModelState.AddModelError(string.Empty, "Please select carMark from list.");
                return(View(model));
            }
            if (ModelState.IsValid & CheckUniqueValues(model.Entity))
            {
                model.Entity.CarMarkId = carMark.CarMarkId;
                await db.CarModels.AddAsync(model.Entity);

                await db.SaveChangesAsync();

                cache.Clean();

                return(RedirectToAction("Index", "CarModels"));
            }

            return(View(model));
        }