Example #1
0
        public static MottorModelViewModel MottoEntityToViewModel(MottorModel model)
        {
            var entity = new MottorModelViewModel()
            {
                Id    = model.Id,
                Name  = model.Name,
                Total = model.Total,
                Date  = model.Date,
                Make  = model.Make
            };

            return(entity);
        }
Example #2
0
        public static MottorModel ViewModelToMottoEntity(MottorModelViewModel model)
        {
            var entity = new MottorModel()
            {
                Id    = model.Id >= 1 ? model.Id : 0,
                Name  = model.Name.ToUpper(),
                Date  = DateTime.UtcNow,
                Make  = model.Make.ToUpper(),
                Total = model.Total
            };

            return(entity);
        }
Example #3
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 #4
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 #5
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 #6
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));;
        }