Example #1
0
        public ActionResult Index()
        {
            //var driverViewModel =new DriverViewModel();
            var model = _dbContext.MottoModels
                        .ToList()
                        .Select(g => MottoModelFactory.MottoEntityToViewModel(g));

            return(View(model));
            //return Json(new { data = drivers }, JsonRequestBehavior.AllowGet);
        }
Example #2
0
        public async Task <ActionResult> Edit(MottorModelViewModel model)
        {
            if (ModelState.IsValid)
            {
                MottorModel modelDriver = MottoModelFactory.ViewModelToMottoEntity(model);

                _dbContext.Entry(modelDriver).State = EntityState.Modified;
                await _dbContext.SaveChangesAsync();

                Success("Model Updated Successfully", true);
                return(Json(new { success = true }));
            }

            return(PartialView("_Edit", model));
        }
Example #3
0
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MottorModel motto = await _dbContext.MottoModels.FindAsync(id);

            if (motto == null)
            {
                return(HttpNotFound());
            }

            MottorModelViewModel mottoModelViewModel = MottoModelFactory.MottoEntityToViewModel(motto);

            return(PartialView("_Delete", mottoModelViewModel));
        }
Example #4
0
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            MottorModel driver = await _dbContext.MottoModels.FindAsync(id);

            if (driver == null)
            {
                return(HttpNotFound());
            }

            MottorModelViewModel driverViewModel = MottoModelFactory.MottoEntityToViewModel(driver);


            return(PartialView("_Edit", driverViewModel));
        }
Example #5
0
        public async Task <ActionResult> Create(MottorModelViewModel model)
        {
            //Check the validity of the model
            if (ModelState.IsValid)
            {
                // call an instance of Driver Class
                var driver = MottoModelFactory.ViewModelToMottoEntity(model);

                _dbContext.MottoModels.Add(driver);
                await _dbContext.SaveChangesAsync();

                Success("Creted Successfully", true);
                return(Json(new { success = true }));
            }



            return(PartialView("_Create", model));;
        }