public async Task <ActionResult> SaveVehicleGearBoxOilMilage([FromBody] VehicleGearBoxOilMilageViewModel vm) { var userName = identityService.GetUserName(); var response = await _vehicleGearBoxOilMilageService.SaveVehicleGearBoxOilMilage(vm, userName); return(Ok(response)); }
public async Task<ResponseViewModel> AddNewVehicleGearBoxOilMilageRecord(VehicleGearBoxOilMilageViewModel vm, string userName) { var response = new ResponseViewModel(); try { var user = _userService.GetUserByUsername(userName); var vgbom = vm.ToModel(); vgbom.UpdatedBy = user.Id; vgbom.CreatedBy = user.Id; _db.VehicleGearBoxOilMilages.Add(vgbom); await _db.SaveChangesAsync(); response.IsSuccess = true; response.Message = "New Vehicle Gear Box Oil Milage has been added."; } catch (Exception ex) { response.IsSuccess = false; response.Message = "Operation failed.Please try again."; } return response; }
public async Task <VehicleResponseViewModel> SaveVehicleGearBoxOilMilage(VehicleGearBoxOilMilageViewModel vm, string userName) { var response = new VehicleResponseViewModel(); try { var user = _userService.GetUserByUsername(userName); var model = _db.VehicleGearBoxOilMilages.FirstOrDefault(x => x.Id == vm.Id); if (model == null) { model = vm.ToModel(); model.CreatedBy = user.Id; model.UpdatedBy = user.Id; _db.VehicleGearBoxOilMilages.Add(model); response.Message = "New Record has been added."; } else { model.GearBoxOilChangeMilage = vm.GearBoxOilChangeMilage; model.NextGearBoxOilChangeMilage = vm.NextGearBoxOilChangeMilage; model.UpdatedBy = user.Id; model.UpdatedOn = DateTime.UtcNow; model.Note = vm.Note; _db.VehicleGearBoxOilMilages.Update(model); response.Message = "Record has been updated."; } await _db.SaveChangesAsync(); response.IsSuccess = true; } catch (Exception ex) { _logger.LogError(ex.ToString()); response.IsSuccess = false; response.Message = "Operation failed.Please try again."; } return(response); }
public static VehicleGearBoxOilMilage ToModel(this VehicleGearBoxOilMilageViewModel vm, VehicleGearBoxOilMilage model = null) { if (model == null) { model = new VehicleGearBoxOilMilage(); } model.Id = vm.Id; model.VehicleId = vm.VehicleId; model.NextGearBoxOilChangeMilage = vm.NextGearBoxOilChangeMilage; model.GearBoxOilChangeMilage = vm.GearBoxOilChangeMilage; model.CreatedOn = DateTime.UtcNow; model.UpdatedOn = DateTime.UtcNow; model.Note = vm.Note; model.IsActive = vm.IsActive; return(model); }
public static VehicleGearBoxOilMilageViewModel ToVm(this VehicleGearBoxOilMilage model, VehicleGearBoxOilMilageViewModel vm = null) { if (vm == null) { vm = new VehicleGearBoxOilMilageViewModel(); } vm.Id = model.Id; vm.VehicleId = model.VehicleId; vm.NextGearBoxOilChangeMilage = model.NextGearBoxOilChangeMilage; vm.GearBoxOilChangeMilage = model.GearBoxOilChangeMilage; vm.CreatedOn = model.CreatedOn.ToString("MMMM dd, yyyy"); vm.UpdatedOn = model.UpdatedOn.ToString("MMMM dd, yyyy"); vm.CreatedBy = string.Format("{0} {1}", model.CreatedByNavigation.FirstName, model.CreatedByNavigation.LastName); vm.UpdatedBy = string.Format("{0} {1}", model.UpdatedByNavigation.FirstName, model.UpdatedByNavigation.LastName); vm.IsActive = model.IsActive; vm.Note = model.Note; vm.RegistrationNo = model.Vehicle.RegistrationNo; return(vm); }