public IActionResult AddUpdateHorse(HorseAddRequest horseAddRequest) { string actionBy = User.Identity.Name; _mainResponse = _horseService.AddUpdateHorse(horseAddRequest, actionBy); _jsonString = Mapper.Convert <BaseResponse>(_mainResponse); return(new OkObjectResult(_jsonString)); }
public MainResponse AddUpdateHorse(HorseAddRequest horseAddRequest, string actionBy) { if (horseAddRequest.HorseId == 0) { var horseExist = _horseRepository.GetSingle(x => x.Name == horseAddRequest.Name && x.IsActive == true && x.IsDeleted == false); if (horseExist != null && horseExist.HorseId > 0) { _mainResponse.Message = Constants.HORSE_EXIST; _mainResponse.Success = false; return(_mainResponse); } var horse = new Horses { Name = horseAddRequest.Name, HorseTypeId = horseAddRequest.HorseTypeId, JumpHeightId = horseAddRequest.JumpHeightId, GroupId = horseAddRequest.GroupId, NSBAIndicator = horseAddRequest.NSBAIndicator, IsActive = true, CreatedBy = actionBy, CreatedDate = DateTime.Now }; var _horse = _horseRepository.Add(horse); _mainResponse.NewId = _horse.HorseId; _mainResponse.Message = Constants.HORSE_ADDED; _mainResponse.Success = true; } else { var horse = _horseRepository.GetSingle(x => x.HorseId == horseAddRequest.HorseId && x.IsActive == true && x.IsDeleted == false); if (horse != null) { horse.Name = horseAddRequest.Name; horse.HorseTypeId = horseAddRequest.HorseTypeId; horse.GroupId = horseAddRequest.GroupId; horse.JumpHeightId = horseAddRequest.JumpHeightId; horse.NSBAIndicator = horseAddRequest.NSBAIndicator; horse.ModifiedBy = actionBy; horse.ModifiedDate = DateTime.Now; _horseRepository.Update(horse); _mainResponse.NewId = horseAddRequest.HorseId; _mainResponse.Message = Constants.HORSE_UPDATED; _mainResponse.Success = true; } else { _mainResponse.Success = false; _mainResponse.Message = Constants.NO_RECORD_FOUND; } } return(_mainResponse); }