コード例 #1
0
    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;
    }
コード例 #2
0
        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);
        }