Exemplo n.º 1
0
    public async Task<ResponseViewModel> AddNewVehicleAirCleanerRecord(VehicleAirCleanerViewModel vm, string userName)
    {
      var response = new ResponseViewModel();
      try
      {
        var user = _userService.GetUserByUsername(userName);

        var vac = vm.ToModel();
        vac.UpdatedBy = user.Id;
        vac.CreatedBy = user.Id;

        _db.VehicleAirCleaners.Add(vac);
        await _db.SaveChangesAsync();

        response.IsSuccess = true;
        response.Message = "New Vehicle Air Cleaner Record has been added.";
      }
      catch (Exception ex)
      {
        logger.LogError(ex.ToString());
        response.IsSuccess = false;
        response.Message = "Operation failed.Please try again.";
      }


      return response;
    }
Exemplo n.º 2
0
        public async Task <VehicleResponseViewModel> SaveVehicleAirCleaner(VehicleAirCleanerViewModel vm, string userName)
        {
            var response = new VehicleResponseViewModel();

            try
            {
                var user  = _userService.GetUserByUsername(userName);
                var model = _db.VehicleAirCleaners.FirstOrDefault(x => x.Id == vm.Id);
                if (model == null)
                {
                    model           = vm.ToModel();
                    model.CreatedBy = user.Id;
                    model.UpdatedBy = user.Id;
                    _db.VehicleAirCleaners.Add(model);
                    response.Message = "New Record has been added.";
                }
                else
                {
                    model.NextAirCleanerReplaceMilage = vm.NextAirCleanerReplaceMilage;
                    model.AirCleanerReplaceMilage     = vm.AirCleanerReplaceMilage;
                    model.UpdatedBy = user.Id;
                    model.UpdatedOn = DateTime.UtcNow;
                    model.Note      = vm.Note;
                    _db.VehicleAirCleaners.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);
        }