public ResponseOut PostRequirement(PostYourRequirement model, int id) { ResponseOut responseOut = new ResponseOut(); using (PortalEntities _context = new PortalEntities()) { try { portal_post_requirement requirement = new portal_post_requirement(); if (id != 0) { var data = _context.portal_user.Where(x => x.pk_user_id == id).FirstOrDefault(); model.email_id = data.email; model.fullname = data.firstname + " " + data.lastname; model.mobile_no = data.contact; requirement.fk_client_id = id; } requirement.email_id = model.email_id; requirement.fullname = model.fullname; requirement.mobile_no = model.mobile_no; requirement.requirement_title = model.requirement_title; requirement.subject = model.subject; requirement.message = model.message; requirement.added_date = DateTime.Now; requirement.project_type = model.project_type; _context.portal_post_requirement.Add(requirement); int result = _context.SaveChanges(); if (result > 0) { responseOut.status = ActionStatus.Success; responseOut.message = ActionMessage.RequirementPost; } } catch (System.Data.Entity.Validation.DbEntityValidationException e) { var outputLines = new List <string>(); foreach (var eve in e.EntityValidationErrors) { outputLines.Add(string.Format( "{0}: Entity of type \"{1}\" in state \"{2}\" has the following validation errors:", DateTime.Now, eve.Entry.Entity.GetType().Name, eve.Entry.State)); foreach (var ve in eve.ValidationErrors) { outputLines.Add(string.Format( "- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage)); } } System.IO.File.AppendAllLines(@"c:\temp\errors.txt", outputLines); } catch (Exception ex) { responseOut.status = ActionStatus.Fail; responseOut.message = ActionMessage.ApplicationException; } return(responseOut); } }
public ResponseOut PostRequirementUpload(PostRequirementImportViewModel data) { ResponseOut responseOut = new ResponseOut(); using (PortalEntities _context = new PortalEntities()) { try { portal_post_requirement _requirement = new portal_post_requirement(); int user_id = 0; if (user_id == 0) { user_id = _context.portal_user.Where(x => !string.IsNullOrEmpty(data.email_id) && x.email.ToLower() == data.email_id.ToLower()).Select(x => x.pk_user_id).FirstOrDefault(); } if (user_id == 0) { user_id = _context.portal_user.Where(x => !string.IsNullOrEmpty(data.contact_details) && x.contact == data.contact_details).Select(x => x.pk_user_id).FirstOrDefault(); } _requirement.mobile_no = data.contact_details; _requirement.email_id = data.email_id; _requirement.fullname = data.client_name; _requirement.added_date = DateTime.Now; _requirement.approved_status = 0; if (user_id != 0) { _requirement.fk_client_id = user_id; } _requirement.subject = data.requirement_title; _requirement.message = data.requirement_description; _context.portal_post_requirement.Add(_requirement); int result = _context.SaveChanges(); if (result > 0) { responseOut.status = ActionStatus.Success; responseOut.message = ActionMessage.RequirementPost; } } catch (Exception ex) { responseOut.status = ActionStatus.Fail; responseOut.message = ActionMessage.ApplicationException; } return(responseOut); } }