/// <summary> /// 添加用户工作经历 /// </summary> /// <param name="working">工作经历</param> public List <WorkingDTO> AddWorking(WorkingDTO working) { var userid = HttpContext.Current.User.Identity.Name; using (var db = new AspodesDB()) { var userInfo = db.Users.FirstOrDefault(c => c.UserId == userid); if (userInfo != null) { working.WorkingId = Guid.NewGuid().ToString("D");; List <WorkingDTO> workingList = new List <WorkingDTO>(); if (!string.IsNullOrEmpty(userInfo.Person.WorkingHistory)) { workingList = JsonConvert.DeserializeObject <List <WorkingDTO> >(userInfo.Person.WorkingHistory); } workingList.Add(working); userInfo.Person.WorkingHistory = JsonConvert.SerializeObject(workingList); db.SaveChanges(); return(workingList); } else { throw new NotFoundException("找不到用户!"); } } }
public HttpResponseMessage Put(WorkingDTO working) { try { return(ResponseWrapper.SuccessResponse(repository.EditWorking(working))); } catch (Exception e) { return(ResponseWrapper.ExceptionResponse(e)); } }
/// <summary> /// 修改用户工作经历 /// </summary> /// <param name="working">工作经历</param> public List <WorkingDTO> EditWorking(WorkingDTO working) { var userid = HttpContext.Current.User.Identity.Name; using (var db = new AspodesDB()) { var userInfo = db.Users.FirstOrDefault(c => c.UserId == userid); if (userInfo != null) { ; if (!string.IsNullOrEmpty(userInfo.Person.WorkingHistory)) { List <WorkingDTO> workingList = JsonConvert.DeserializeObject <List <WorkingDTO> >(userInfo.Person.WorkingHistory); var workingdata = workingList.FirstOrDefault(c => c.WorkingId == working.WorkingId); if (workingdata != null) { workingList.Remove(workingdata); workingList.Add(working); userInfo.Person.WorkingHistory = JsonConvert.SerializeObject(workingList); db.SaveChanges(); return(workingList); } else { throw new NotFoundException("该工作经历不存在!"); } } else { throw new NotFoundException("无工作经历!"); } } else { throw new NotFoundException("找不到用户!"); } } }