public async Task CreateOrUpdateActivity(ActivityInputDto input) { if (input.Id != 0) { await UpdateActivity(input); } else { await CreateActivity(input); } }
public async Task CreateActivity(ActivityInputDto input) { var act = input.MapTo <Activity>(); var val = _activityRepository .GetAll().Where(p => p.ActivityCode == input.ActivityCode || p.ActivityName == input.ActivityName).FirstOrDefault(); if (val == null) { await _activityRepository.InsertAsync(act); } else { throw new UserFriendlyException("Ooops!", "Duplicate Data Occured in Activity Name '" + input.ActivityName + "' or Activity Code '" + input.ActivityCode + "'..."); } }
public async Task UpdateActivity(ActivityInputDto input) { var act = await _activityRepository.GetAsync(input.Id); ObjectMapper.Map(input, act); var val = _activityRepository .GetAll().Where(p => (p.ActivityCode == input.ActivityCode || p.ActivityName == input.ActivityName) && p.Id != input.Id).FirstOrDefault(); if (val == null) { await _activityRepository.UpdateAsync(act); } else { throw new UserFriendlyException("Ooops!", "Duplicate Data Occured in Activity Name '" + input.ActivityName + "' or Activity Code '" + input.ActivityCode + "'..."); } }