Ejemplo n.º 1
0
        public static MilageViewModel EntityToViewModel(Milage model)
        {
            var milage = new MilageViewModel(model)
            {
            };

            return(milage);
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Edit(MilageViewModel model)
        {
            using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    Milage milage = MilageFactory.MilageViewmodelToEntity(model);

                    if (milage == null)
                    {
                        Danger("Milage cannot be found", true);
                        return(Json(new { success = true }));
                    }
                    _context.Entry(milage).State = EntityState.Modified;
                    await _context.SaveChangesAsync();

                    // get the vehicle movement through their id
                    var getVehicleMovement =
                        _context.VehicleMovements.SingleOrDefault(x => x.Id.Equals(model.VehicleMovementId));

                    var driver = _context.Drivers.SingleOrDefault(x => x.Id.Equals(getVehicleMovement.DriverId));

                    if (driver == null)
                    {
                        Danger("Driver cannot be found", true);
                        return(Json(new { success = true }));
                    }

                    driver.IsAvailable = true;
                    await _context.SaveChangesAsync();

                    var getMottor = _context.Mottors.SingleOrDefault(x => x.Id.Equals(getVehicleMovement.MotoId));
                    if (getMottor == null)
                    {
                        Danger("Mottor cannot be found", true);
                        return(Json(new { success = true }));
                    }

                    getMottor.IsAvailable = true;
                    await _context.SaveChangesAsync();

                    scope.Complete();
                    scope.Dispose();
                    Success("Updated Successfully", true);
                    return(Json(new { success = true }));
                }
                catch (Exception e)
                {
                    Danger(e.Message, true);
                    return(Json(new { success = true }));
                }
            }
        }
Ejemplo n.º 3
0
        public static MilageViewModel EntityToMilageViewModel(Milage model)
        {
            var milage = new MilageViewModel()
            {
                Id                = model.Id,
                MilageIn          = model.MilageIn,
                MilageOut         = model.MilageOut,
                TimeIn            = model.TimeIn.HasValue ? model.TimeIn.Value.ToString("HH:mm tt") : null,
                TimeOut           = model.TimeOut.Value.ToString("HH:mm tt"),
                MilageCovered     = model.MilageCovered,
                VehicleMovementId = model.VehicleMovementId
            };

            return(milage);
        }
Ejemplo n.º 4
0
        public static Milage MilageViewmodelToEntity(MilageViewModel model)
        {
            int milagein  = Int32.Parse(model.MilageIn);
            int milageout = Int32.Parse(model.MilageOut);
            var milage    = new Milage()
            {
                Id                = model.Id,
                TimeOut           = Convert.ToDateTime(model.TimeOut),
                MilageOut         = model.MilageOut,
                VehicleMovementId = model.VehicleMovementId,
                TimeIn            = Convert.ToDateTime(model.TimeIn),
                MilageIn          = model.MilageIn,
                MilageCovered     = Convert.ToString(milagein - milageout)
            };

            return(milage);
        }