private VolunteerDTO Create(VolunteerDataContract dataContract) { try { log.Debug(VolunteerDataContract.FormatVolunteerDataContract(dataContract)); VolunteerDTO volunteer = new VolunteerDTO(); // copy values dataContract.UpdateDTO(volunteer, null); //RequestContext.Principal.Identity.GetUserId()); // audit volunteer.CreateBy = null; //RequestContext.Principal.Identity.GetUserId(); volunteer.CreateOn = DateTime.UtcNow; // add log.Debug("_volunteerService.AddVolunteer - " + VolunteerDTO.FormatVolunteerDTO(volunteer)); int id = _volunteerService.AddVolunteer(volunteer); volunteer.VolunteerId = id; log.Debug("result: 'success', id: " + id); return(volunteer); } catch (Exception e) { // error log.Error(e.ToString()); throw; } }
private VolunteerDTO Update(VolunteerDataContract dataContract) { try { log.Debug(VolunteerDataContract.FormatVolunteerDataContract(dataContract)); // get log.Debug("_volunteerService.GetVolunteer - volunteerId: " + dataContract.VolunteerId + " "); var existingVolunteer = _volunteerService.GetVolunteer(dataContract.VolunteerId); log.Debug("_volunteerService.GetVolunteer - " + VolunteerDTO.FormatVolunteerDTO(existingVolunteer)); if (existingVolunteer != null) { // copy values dataContract.UpdateDTO(existingVolunteer, null); //RequestContext.Principal.Identity.GetUserId()); // update log.Debug("_volunteerService.UpdateVolunteer - " + VolunteerDTO.FormatVolunteerDTO(existingVolunteer)); _volunteerService.UpdateVolunteer(existingVolunteer); log.Debug("result: 'success'"); } else { log.Error("existingVolunteer: null, VolunteerId: " + dataContract.VolunteerId); } return(existingVolunteer); } catch (Exception e) { // error log.Error(e.ToString()); throw; } }
/// <summary> /// Save a list of Volunteer /// </summary> /// <param name="dataContracts">Volunteers</param> /// <param name="id">(not used)</param> /// <returns>true if the operation is successfull</returns> public bool SaveList(VolunteerDataContract[] dataContracts, int?id) { try { log.Debug("SaveList"); if (dataContracts != null) { // save list foreach (VolunteerDataContract dataContract in dataContracts) { log.Debug(VolunteerDataContract.FormatVolunteerDataContract(dataContract)); if (dataContract.VolunteerId > 0) { var t = Update(dataContract); } else { var t = Create(dataContract); } } } else { log.Error("dataContracts: null"); } return(true); } catch (Exception e) { // error log.Error(e.ToString()); throw; } }
/// <summary> /// Get Volunteer by id /// </summary> /// <param name="id">Volunteer id</param> /// <returns>Volunteer</returns> public VolunteerDataContract Get(int id) { try { // get log.Debug("_volunteerService.GetVolunteer - volunteerId: " + id + " "); var volunteer = new VolunteerDataContract(_volunteerService.GetVolunteer(id)); log.Debug("_volunteerService.GetVolunteer - " + VolunteerDataContract.FormatVolunteerDataContract(volunteer)); log.Debug("result: 'success'"); return(volunteer); } catch (Exception e) { // error log.Error(e.ToString()); throw; } }