public RestResponse <OfficerProfile> UpdateOfficer(OfficerProfile officerDetail) { RestResponse <OfficerProfile> restResponse = null; try { var result = repository.FindOne <OfficerProfile>(Constants.OfficersCollection, x => x.OfficerId.Equals(officerDetail.OfficerId), "OfficerId").Result; officerDetail._id = result._id; var result1 = repository.FindOneAndReplace <OfficerProfile>(Constants.OfficersCollection, x => x.OfficerId.Equals(officerDetail.OfficerId), officerDetail); if (result1.Exception == null) { restResponse = Response <OfficerProfile> .ReturnSuccessResponse(); restResponse.ResponseData = officerDetail; } else { restResponse = Response <OfficerProfile> .ReturnFataErrorResponse(); restResponse.ResponseData = new OfficerProfile(); } return(restResponse); } catch (Exception ex) { Logger.Error(ex); restResponse = Response <OfficerProfile> .ReturnFataErrorResponse(); restResponse.ResponseData = new OfficerProfile(); return(restResponse); } }
private OfficerProfileEdit GetOfficerProfileEdit(OfficerProfile officers) { try { var lanInfo = repository.GetAll <LanguageInfo>(Constants.LanguageCollection).Result.ToList(); var specializationInfo = repository.GetAll <Specialization>(Constants.SpecializationCollection).Result.ToList(); OfficerProfileEdit result = new OfficerProfileEdit { WindowsId = officers.WindowsId, Specialization = GetSppecializationInfo(officers.Specialization, specializationInfo), FirstName = officers.FirstName, IsRosterAdministrator = officers.IsRosterAdministrator, LanguagesKnown = GetLanguageInfo(officers.LanguagesKnown, lanInfo), LastName = officers.LastName, OfficerId = officers.OfficerId, RoleId = officers.RoleId, Sex = officers.Sex }; return(result); } catch (Exception ex) { Logger.Error(ex); return(new OfficerProfileEdit()); } }
public RestResponse <OfficerProfile> AddOfficer(OfficerProfile officerDetail) { RestResponse <OfficerProfile> restResponse = null; try { var latestRecord = repository.FindOne <OfficerProfile>(Constants.OfficersCollection, x => x.OfficerId != null, "OfficerId").Result; string[] temp = latestRecord.OfficerId.Split(new string[] { "OFCR" }, StringSplitOptions.None); var latestCount = Convert.ToInt16(temp[1]); var officersID = Constants.OfficerIdPrefix + (latestCount + 1).ToString("D" + 4); officerDetail.OfficerId = officersID; var result = repository.InsertOne(Constants.OfficersCollection, officerDetail); if (result.Exception == null) { restResponse = Response <OfficerProfile> .ReturnSuccessResponse(); restResponse.ResponseData = officerDetail; } else { restResponse = Response <OfficerProfile> .ReturnFataErrorResponse(); restResponse.ResponseData = new OfficerProfile(); } return(restResponse); } catch (Exception ex) { Logger.Error(ex); restResponse = Response <OfficerProfile> .ReturnFataErrorResponse(); restResponse.ResponseData = new OfficerProfile(); return(restResponse); } }