public WorkHistoryDTO PostDeleteWorkHistory(WorkHistoryDTO workHistoryData)
        {
            WorkHistory deletedEntry = new WorkHistory();

            deletedEntry = db.WorkHistories.Where(x => x.workId == workHistoryData.workId).FirstOrDefault();
            if (deletedEntry.workId != Guid.Empty)
            {
                db.WorkHistories.Remove(deletedEntry);
                db.SaveChanges();
            }
            return(MapperFacade.MapperConfiguration.Map <WorkHistory, WorkHistoryDTO>(deletedEntry));
        }
        public WorkHistoryDTO GetworkHistorybyId(Guid workID)
        {
            WorkHistoryDTO getworkHistory = db.WorkHistories.Select(x => new WorkHistoryDTO
            {
                workId          = x.workId,
                workCompanyName = x.workCompanyName,
                workStartDate   = x.workStartDate,
                workEndDate     = x.workEndDate,
                UserRole        = x.UserRole
            }).Where(x => x.workId == workID).FirstOrDefault();

            return(getworkHistory);
        }
 /// <summary>
 /// To Delete Work History
 /// </summary>
 /// <param name="workID"></param>
 /// <returns></returns>
 public ActionResult DeleteWorkHistory(Guid workID)
 {
     using (HttpClientWrapper httpClient = new HttpClientWrapper(Session))
     {
         WorkHistoryDTO objWorkHistory = new WorkHistoryDTO()
         {
             workId = workID
         };
         var deleteWorkHistory = httpClient.PostAsJsonAsync <WorkHistoryDTO>("api/UserProfileAPI/DeleteWorkHistory", objWorkHistory).Result;
         var resultWorkHistory = JsonConvert.DeserializeObject <WorkHistoryDTO>(deleteWorkHistory.Content.ReadAsStringAsync().Result);
         return(Json(new { Success = true, workID = resultWorkHistory.workId }, JsonRequestBehavior.AllowGet));
     };
 }
 /// <summary>
 /// To Update Work History
 /// </summary>
 /// <param name="WHDTO"></param>
 /// <returns></returns>
 public ActionResult AddWorkHistory(WorkHistoryDTO WHDTO)
 {
     using (HttpClientWrapper httpClient = new HttpClientWrapper(Session))
     {
         WorkHistoryDTO objWorkHistory = new WorkHistoryDTO()
         {
             workId          = WHDTO.workId,
             workCompanyName = WHDTO.workCompanyName,
             workStartDate   = WHDTO.workStartDate,
             workEndDate     = WHDTO.workEndDate,
             UserRole        = WHDTO.UserRole
         };
         var updateWorkHistory = httpClient.PostAsJsonAsync <WorkHistoryDTO>("api/UserProfileAPI/AddEditWorkHistory", objWorkHistory).Result;
         var resultWorkHistory = JsonConvert.DeserializeObject <WorkHistoryDTO>(updateWorkHistory.Content.ReadAsStringAsync().Result);
         return(Json(new { Success = true, workHistory = resultWorkHistory }, JsonRequestBehavior.AllowGet));
     };
 }
        public WorkHistoryDTO PostUpdateWorkHistory([FromBody] WorkHistoryDTO workHistoryData)
        {
            var email = HttpContext.Current.User.Identity.Name;

            WorkHistory workHistory = null;

            if (workHistoryData.workId != Guid.Empty)
            {
                workHistory = db.WorkHistories.Where(x => x.workId == workHistoryData.workId).FirstOrDefault();
            }
            else
            {
                workHistory        = new WorkHistory();
                workHistory.workId = Guid.NewGuid();
            }

            workHistory.workCompanyName = workHistoryData.workCompanyName;
            workHistory.workStartDate   = workHistoryData.workStartDate;
            workHistory.workEndDate     = workHistoryData.workEndDate;
            workHistory.UserProfile     = db.UserProfiles.FirstOrDefault(usr => usr.Email == email);
            workHistory.UserRole        = workHistoryData.UserRole;

            if (workHistory == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            if (workHistoryData.workId == Guid.Empty)
            {
                db.WorkHistories.Add(workHistory);
            }

            db.SaveChanges();
            WorkHistoryDTO employeeDTO = MapperFacade.MapperConfiguration.Map <WorkHistory, WorkHistoryDTO>(workHistory);

            return(employeeDTO);
        }