public ActionResult AddFamilyMember(Family family) { try { if (Session["family"] != null) { AddMultipleMembers(); } int Id = Convert.ToInt32(HttpContext.Session["UserID"]); int count = service.GetEntireFamily(Id).Count(); try { while (count <= 5) { var config = new MapperConfiguration(cfg => cfg.CreateMap <Family, WCP_Family>()); var map = config.CreateMapper(); var data = map.Map <Family, WCP_Family>(family); if (count == 0) { Session["MinDate"] = data.dob; } else { Session["MinDate"] = 1900 - 01 - 01; } int familyMemberId = service.AddFamilyMember(data); TempData["familyMemberId"] = familyMemberId; int id = Convert.ToInt32(Session["UserId"]); service.AddFamilyRelation(id, familyMemberId); var urlBuilder = new UrlHelper(Request.RequestContext); var url = urlBuilder.Action("AddMemberCategory", "FamilyMap"); return(Json(new { status = "success" })); } } catch { } return(Json(new { status = "error" })); } catch (Exception exception) { return(RedirectToAction("ExceptionPage", new { message = exception.Message })); } }