public HttpResponseMessage Get(int id) { //Let us Initiate the model with UniqueId and the Franchisee Id var data = new TBL_CONTACTS() { CONTACTSID= 0, COMPANYID=0}; if (id > 0) { data = uow.Repository<TBL_CONTACTS>().GetById(id); } return Request.CreateResponse(data); }
public genericResponse ArchiveContact(TBL_CONTACTS _contact) { genericResponse _response; try { if (uow.ContactRepository().ArchiveContact(_contact.CONTACTSID, CurrentUser.UserId.ToString())) { _response = new genericResponse() { success = true }; return _response; } else { _response = new genericResponse() { success = false, message = "There is a problem Archiving this Contact Record. Please try again later." }; return _response; } } catch { _response = new genericResponse() { success = false, message = "There is a problem Archiving this Contact Record. Please try again later." }; return _response; } }
public HttpResponseMessage SaveContact(TBL_CONTACTS contact) { try { //List<ContactView> contacts = uow.ContactRepository().Get("LastName ASC", 0, 0, null, CurrentUser.FranchiseeID, null, CurrentUser.UserId.ToString(), "", false).Where(r => r.FirstName == contact.FIRSTNAME && r.LastName == contact.LASTNAME && r.CompanyId == contact.COMPANYID).ToList<ContactView>(); ; List<ContactView> contacts = uow.ContactRepository().Get("LastName ASC", 0, 0, null, CurrentUser.FranchiseeID, null,"", "", false).Where(r => r.FirstName == contact.FIRSTNAME && r.LastName == contact.LASTNAME && r.CompanyId == contact.COMPANYID).ToList<ContactView>(); TBL_CONTACTS tmpContact; if (contacts.Count > 0) { tmpContact = uow.Repository<TBL_CONTACTS>().GetById(contacts[0].ContactsId); } else { tmpContact = new TBL_CONTACTS(); } tmpContact.COMPANYID = contact.COMPANYID; tmpContact.CourseTrainingDate = contact.CourseTrainingDate; tmpContact.NEXT_CONTACT_DATE = contact.NEXT_CONTACT_DATE; tmpContact.ApptSourceId = contact.ApptSourceId; tmpContact.IsNewAppointment = contact.IsNewAppointment; tmpContact.IsRegisteredForTraining = contact.IsRegisteredForTraining; tmpContact.CourseId = contact.CourseId; tmpContact.TrainingCourseName = contact.TrainingCourseName; tmpContact.HowManyAttended = contact.HowManyAttended; tmpContact.ACTIONSTEP = contact.ACTIONSTEP; tmpContact.FIRSTNAME = contact.FIRSTNAME; tmpContact.LASTNAME = contact.LASTNAME; tmpContact.PHONE = contact.PHONE; tmpContact.EMAIL = contact.EMAIL; contact = tmpContact; if (!VerifyContactRequiredFields(contact)) throw new Exception("Contact required fields are not submiited"); if (contact.CONTACTSID > 0) { contact.UpdatedBy = CurrentUser.UserId.ToString(); contact.UpdatedDate = DateTime.Now; uow.Repository<TBL_CONTACTS>().Update(contact); } else { contact.CreatedBy = CurrentUser.UserId.ToString(); contact.CreatedDate = DateTime.Now; contact.IsActive = true; uow.Repository<TBL_CONTACTS>().Add(contact); } uow.Save(); return Request.CreateResponse(contact); } catch (Exception ex) { throw new Exception("There is a problem in Saving Contact Information. Please try again later.", ex); } }
private bool VerifyContactRequiredFields(TBL_CONTACTS contact) { bool trainingcheck = true; if (contact.IsRegisteredForTraining.HasValue == true && contact.IsRegisteredForTraining.Value == true) trainingcheck = (contact.CourseId > 0 && !string.IsNullOrEmpty(contact.TrainingCourseName) && contact.CourseTrainingDate.HasValue && contact.HowManyAttended > 0); return trainingcheck && (contact.COMPANYID > 0 && !string.IsNullOrEmpty(contact.FIRSTNAME) && !string.IsNullOrEmpty(contact.LASTNAME) && contact.ApptSourceId > 0); }
private bool VerifyRequiredFields(TBL_CONTACTS contact) { return (!string.IsNullOrEmpty(contact.FIRSTNAME) && !string.IsNullOrEmpty(contact.LASTNAME)); }
public HttpResponseMessage Save(TBL_CONTACTS contact) { if (!VerifyRequiredFields(contact)) return new HttpResponseMessage(HttpStatusCode.InternalServerError); if (contact.CONTACTSID > 0) { uow.Repository<TBL_CONTACTS>().Update(contact); contact.UpdatedBy = CurrentUser.UserId.ToString(); contact.UpdatedDate = DateTime.Now; } else { contact.CreatedBy = CurrentUser.UserId.ToString(); contact.CreatedDate = DateTime.Now; contact.IsActive = true; uow.Repository<TBL_CONTACTS>().Add(contact); } uow.Save(); return Request.CreateResponse(contact); }