public FindItemReponse <YouthScholarshipModel> FindByUserID(string userID) { try { IYouthScholarshipRepository youthScholarshipRepository = RepositoryClassFactory.GetInstance().GetYouthShcolarshipReoisitory(); IMailingAddressRepository mailingRepository = RepositoryClassFactory.GetInstance().GetMailingAddressRepository(); YouthScholarship scholarship = youthScholarshipRepository.FindByUserID(userID); var _scholarship = MapperUtil.CreateMapper().Mapper.Map <YouthScholarship, YouthScholarshipModel>(scholarship); if (_scholarship != null) { IList <MailingAddress> _mailings = mailingRepository.FindByUserID(userID); if (_mailings != null && _mailings.Count > 0) { _scholarship.RegistrationNumber = _mailings.FirstOrDefault().RegistrationNumber; } } return(new FindItemReponse <YouthScholarshipModel> { Item = _scholarship, ErrorCode = (int)ErrorCode.None, Message = string.Empty }); } catch (Exception ex) { return(new FindItemReponse <YouthScholarshipModel> { ErrorCode = (int)ErrorCode.Error, Message = ex.Message }); } }
public object Insert(YouthScholarship item) { using (APCRSHREntities context = new APCRSHREntities()) { context.YouthScholarships.Add(item); context.SaveChanges(); return(item.YouthScholarshipID); } }
public DataModel.Response.FindItemReponse <DataModel.Model.YouthScholarshipModel> FindByID(string id) { try { IYouthScholarshipRepository youthScholarshipRepository = RepositoryClassFactory.GetInstance().GetYouthShcolarshipReoisitory(); YouthScholarship scholarship = youthScholarshipRepository.FindByID(id); var _scholarship = MapperUtil.CreateMapper().Mapper.Map <YouthScholarship, YouthScholarshipModel>(scholarship); return(new FindItemReponse <YouthScholarshipModel> { Item = _scholarship, ErrorCode = (int)ErrorCode.None, Message = string.Empty }); } catch (Exception ex) { return(new FindItemReponse <YouthScholarshipModel> { ErrorCode = (int)ErrorCode.Error, Message = ex.Message }); } }
public void Update(YouthScholarship item) { using (APCRSHREntities context = new APCRSHREntities()) { var scholarship = context.YouthScholarships.Where(a => a.YouthScholarshipID.Equals(item.YouthScholarshipID)).SingleOrDefault(); if (scholarship != null) { scholarship.MotivationIssue = item.MotivationIssue; scholarship.MotivationReason = item.MotivationReason; scholarship.MotivationResolving = item.MotivationResolving; scholarship.PlanMaking = item.PlanMaking; scholarship.UpdatedBy = item.UpdatedBy; scholarship.UpdatedDate = DateTime.Now; scholarship.UploadFile = !string.IsNullOrEmpty(item.UploadFile) ? item.UploadFile : scholarship.UploadFile; scholarship.UserID = item.UserID; context.SaveChanges(); } else { throw new Exception(string.Format("Youth scholarship id {0} invalid", item.YouthScholarshipID)); } } }