Beispiel #1
0
        public static bool isPlateNumberAlreadyExisting(Mottor model, MottorViewModel viewModel)
        {
            if (model.PlateNumber.Trim() == viewModel.PlateNumber.Trim())
            {
                return(true);
            }

            return(false);
        }
Beispiel #2
0
 public MottorViewModel(Mottor model)
 {
     this.Id              = model.Id;
     this.MottorModelId   = model.MottorModel.Id;
     this.MottorModelName = model.MottorModel.Name;
     this.PlateNumber     = model.PlateNumber;
     this.IsAvailable     = model.IsAvailable;
     this.VehicleId       = model.Vehicle.Id;
     this.VehicleName     = model.Vehicle.Type;
     this.DepartmentId    = model.Department.Id;
     this.DepartmentName  = model.Department.Name;
     this.modelMake       = model.MottorModel.Make;
     this.DateCreated     = DateTime.UtcNow;
 }
Beispiel #3
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);
        }
Beispiel #4
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));
        }
Beispiel #5
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);
        }
Beispiel #6
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));
        }
Beispiel #7
0
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Mottor mottor = await _context.Mottors.FindAsync(id);

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

            var model = MottorFactory.MottoEntityToViewModelFOrEdit(mottor);

            setModeList(model);
            return(PartialView("_Edit", model));
        }
Beispiel #8
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            try
            {
                Mottor model = await _context.Mottors.FindAsync(id);

                if (model != null)
                {
                    _context.Mottors.Remove(model);
                }
                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                Danger(e.Message, true);
                return(Json(new { success = true }));
            }

            Success("Model Deleted Successfully", true);
            return(Json(new { success = true }));
        }
Beispiel #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));
        }
Beispiel #10
0
        public static MottorViewModel MottoEntityToViewModel(Mottor model)
        {
            var entity = new MottorViewModel(model);

            return(entity);
        }