示例#1
0
        public ActionResult Create()
        {
            var model = new MottorViewModel();

            setModeList(model);
            return(PartialView("_Create", model));
        }
示例#2
0
        public static bool isPlateNumberAlreadyExisting(Mottor model, MottorViewModel viewModel)
        {
            if (model.PlateNumber.Trim() == viewModel.PlateNumber.Trim())
            {
                return(true);
            }

            return(false);
        }
示例#3
0
        // Private function
        private MottorViewModel setModeList(MottorViewModel model)
        {
            var departments = _context.Departments.ToList();
            var models      = _context.MottoModels.ToList();
            var vehicles    = _context.Vehicles.ToList();

            model.SelectLists(departments, models, vehicles);

            return(model);
        }
示例#4
0
        public static MottorViewModel MottoEntityToViewModelFOrEdit(Mottor model)
        {
            var motto = new MottorViewModel()
            {
                Id            = model.Id,
                MottorModelId = model.MottorModelId,

                PlateNumber  = model.PlateNumber,
                IsAvailable  = model.IsAvailable,
                VehicleId    = model.VehicleId,
                DepartmentId = model.DepartmentId,
            };

            return(motto);
        }
示例#5
0
        public async Task <ActionResult> Edit(MottorViewModel model)
        {
            if (ModelState.IsValid)
            {
                Mottor motto = MottorFactory.ViewModelToMottoEntity(model);

                _context.Entry(motto).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                Success("Motto with the plate number : " + motto.PlateNumber + "   Updated Successfully", true);
                return(Json(new { success = true }));
            }

            return(PartialView("_Edit", model));
        }
示例#6
0
        public static Mottor ViewModelToMottoEntity(MottorViewModel model)
        {
            var entity = new Mottor()
            {
                Id            = model.Id >= 1 ? model.Id : 0,
                DepartmentId  = model.DepartmentId,
                VehicleId     = model.VehicleId,
                MottorModelId = model.MottorModelId,
                PlateNumber   = model.PlateNumber.ToUpper(),
                IsAvailable   = model.IsAvailable,
                DateCreated   = DateTime.UtcNow
                                // VehicleMovements =
            };

            return(entity);
        }
示例#7
0
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Mottor motto = await _context.Mottors.FindAsync(id);

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

            MottorViewModel mottoViewModel = MottorFactory.MottoEntityToViewModelFOrEdit(motto);

            return(PartialView("_Delete", mottoViewModel));
        }
示例#8
0
        public async Task <ActionResult> Create(MottorViewModel model)
        {
            //Check the validity of the model
            if (ModelState.IsValid)
            {
                try
                {
                    bool isPlateNumberExist = false;
                    // search for plate number
                    var allMottors = _context.Mottors
                                     .ToList()
                                     .FirstOrDefault(x => x.PlateNumber.ToLower().Trim() == model.PlateNumber.ToLower().Trim());
                    if (allMottors != null)
                    {
                        isPlateNumberExist = MottorFactory.isPlateNumberAlreadyExisting(allMottors, model);
                    }
                    //ValidateRequest plate number

                    //redirect to index
                    if (isPlateNumberExist == true)
                    {
                        Warning("Mottor  with plate number " + model.PlateNumber + " is already existing ", true);
                        return(Json(new { success = true }));
                    }
                    var motto = MottorFactory.ViewModelToMottoEntity(model);

                    _context.Mottors.Add(motto);
                    var i = await _context.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    Danger(ex.Message, true);
                    return(Json(new { success = true }));
                }
                // call an instance of Driver Class

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



            return(PartialView("_Create", model));
        }
示例#9
0
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            //find model
            Mottor model = await _context.Mottors.FindAsync(id);

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

            //validate all by including all the vehicle
            var singleOrDefault = _context.Mottors
                                  .Include(x => x.Department)
                                  .Include(x => x.Vehicle)
                                  .Include(x => x.MottorModel)
                                  .FirstOrDefault(x => x.Id == model.Id);

            // check if such mottor cannot be found.
            if (singleOrDefault == null)
            {
                Warning("Cannot find such mottor", true);
                return(Json(new { success = true }));
            }

            model = singleOrDefault;



            MottorViewModel mottoViewModel = MottorFactory.MottoEntityToViewModel(model);

            return(PartialView("_Details", mottoViewModel));
        }
示例#10
0
        public static MottorViewModel MottoEntityToViewModel(Mottor model)
        {
            var entity = new MottorViewModel(model);

            return(entity);
        }