public JsonResult SaveItemContact(string _peopleModel)
        {
            //ViewBag.PeopleModelItem = _peopleModel;
            Logger.Debug("Inside People Controller- SaveItem");
            JsonResult result = new JsonResult();
            try
            {
                System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();
                var people = js.Deserialize<dynamic>(_peopleModel);
                PeopleModel People = new PeopleModel();
                People.FirstName = people["FirstName"];
                People.LastName = people["LastName"];
                People.MobilePhone = people["MobilePhone"];
                People.BusinessPhone = people["BusinessPhone"];
                People.HomePhone = people["HomePhone"];
                People.Emails = people["Email"];
                People.AddressLine1 = people["Address1"];
                People.AddressLine2 = people["Address2"];
                People.City = people["City"];
                People.State = people["State"];
                People.Country = people["Country"];
                People.ZipCode = people["ZipCode"];

                TempData["PeopleModel"] = People;
                result.Data = "success";
                result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
                return result;
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                result.Data = "failure";
                return result;
            }
            //  return View("Create",Create(people["ID"], );
            //  people["ID"] 

        }
 public ActionResult Delete(string id = "", string customerguid = "")
 {
     Logger.Debug("Inside People Controller- Delete");
     try
     {
         if (Session["OrganizationGUID"] != null)
         {
             PeopleModel people = new PeopleModel();
             people.PeopleGUID = id;
             _IPeopleRepository.DeletePeople(new Guid(people.PeopleGUID));
             // _IPeopleRepository.Save();
             //string placeGUID = _IPeopleRepository.GetPeopleByID(new Guid(people.PeopleGUID)).PlaceGUID.ToString();
             return RedirectToAction("Index", "CustomerView", new { id = "Contacts", customerid = customerguid });
         }
         else
         {
             return RedirectToAction("SessionTimeOut", "User");
         }
     }
     catch (Exception ex)
     {
         Logger.Error(ex.Message);
         return RedirectToAction("Index");
     }
 }
        public ActionResult Contact(PeopleViewForCreate peoplecreate)
        {
            Logger.Debug("Inside Place Controller- Create Http Post");
            try
            {
                if (Session["OrganizationGUID"] != null)
                {
                    if (ModelState.IsValid)
                    {
                        PeopleModel people = new PeopleModel();
                        people = peoplecreate.PeopleModel;
                        Person People = new Person();
                        People.PeopleGUID = Guid.NewGuid();

                        People.UserGUID = new Guid(people.UserGUID.ToString());
                        if (!string.IsNullOrEmpty(people.OrganizationGUID.ToString()) && people.OrganizationGUID != Guid.Empty.ToString())
                        {
                            People.OrganizationGUID = new Guid(people.OrganizationGUID.ToString());
                        }
                        else
                        {
                            People.OrganizationGUID = null;
                        }
                        People.IsPrimaryContact = true;
                        if (!string.IsNullOrEmpty(people.PlaceGUID.ToString()) && people.PlaceGUID != Guid.Empty.ToString())
                        {
                            People.PlaceGUID = new Guid(people.PlaceGUID.ToString());
                        }
                        else
                        {
                            People.PlaceGUID = null;
                        }
                        People.FirstName = people.FirstName;
                        People.LastName = people.LastName;
                        People.MobilePhone = people.MobilePhone;
                        People.CompanyName = people.CompanyName;
                        People.BusinessPhone = people.BusinessPhone;
                        People.HomePhone = people.HomePhone;
                        People.Emails = people.Emails;
                        People.AddressLine1 = people.AddressLine1;
                        People.AddressLine2 = people.AddressLine2;
                        People.City = people.City;
                        People.State = people.State;
                        People.Country = people.Country;
                        People.ZipCode = people.ZipCode;
                        People.CategoryID = 0;
                        People.IsDeleted = false;
                        People.CreatedDate = DateTime.UtcNow;
                        People.UpdatedDate = DateTime.UtcNow;


                        int peopleInsertResult = _IPeopleRepository.InsertPeople(People);
                        //int peopleInsertResult = _IPeopleRepository.Save();
                        if (peopleInsertResult > 0)
                        {
                            ContactValues contactValues = new ContactValues();
                            contactValues.UserGUID = People.UserGUID;
                            contactValues.OrganizationGUID = People.OrganizationGUID != null ? new Guid(People.OrganizationGUID.ToString()) : Guid.Empty;
                            contactValues.OwnerGUID = People.PlaceGUID != null ? new Guid(People.PlaceGUID.ToString()) : Guid.Empty;
                            contactValues.PrimaryContactGUID = People.PeopleGUID;
                            contactValues.ContactName = People.FirstName;
                            TempData["ContactDetails"] = contactValues;
                            return RedirectToAction("Create");
                        }
                        else
                        {
                            return View(peoplecreate);
                        }

                    }
                    else
                    {
                        var userList = new AspNetUserViewModel();
                        userList.Users = new List<AspUser>();
                        var appUser = _IUserProfileRepository.GetUserProfilesbyOrganizationGUID(new Guid(Session["OrganizationGUID"].ToString())).OrderBy(sort => sort.FirstName).ToList();
                        //if (string.IsNullOrEmpty(id))
                        {
                            userList.Users.Add(new AspUser { FirstName = "All", LastName = "", UserGUID = Guid.Empty.ToString(), OrganizationGUID = "" });
                            foreach (var user in appUser.ToList())
                            {
                                userList.Users.Add(new AspUser { FirstName = user.FirstName, LastName = user.LastName, UserGUID = user.UserGUID.ToString() });
                            }
                        }

                        var placeList = new PlaceViewModel();
                        placeList.PlaceList = new List<PlaceModel>();
                        var appPlace = new List<Place>();

                        appPlace = _IPlaceRepository.GetPlaceByOrganizationGUID(new Guid(Session["OrganizationGUID"].ToString())).ToList();
                        foreach (var place in appPlace.ToList())
                        {
                            placeList.PlaceList.Add(new PlaceModel
                            {
                                PlaceGUID = place.PlaceGUID.ToString(),
                                PlaceID = place.PlaceID,
                                PlaceName = place.PlaceName,
                                PlacePhone = place.PlacePhone,
                                FirstName = place.FirstName,
                                LastName = place.LastName,
                                UserGUID = place.UserGUID.ToString(),
                                OrganizationGUID = place.OrganizationGUID != null ? place.OrganizationGUID.ToString() : Guid.Empty.ToString(),
                                MobilePhone = place.MobilePhone,
                                HomePhone = place.HomePhone,
                                Emails = place.Emails,
                                TimeZone = place.TimeZone,
                                AddressLine1 = place.AddressLine1,
                                AddressLine2 = place.AddressLine2,
                                City = place.City,
                                State = place.State,
                                Country = place.Country,
                                ZipCode = place.ZipCode

                            });
                        }
                        var placeviewModel = new PlaceViewModel();
                        placeviewModel.Place = placeList.PlaceList.AsEnumerable();
                        placeviewModel.User = userList.Users.AsEnumerable();

                        var PeopleViewForCreate = new PeopleViewForCreate();
                        PeopleViewForCreate.PlaceViewModel = placeviewModel;
                        return View(PeopleViewForCreate);
                    }
                }
                else
                {
                    return RedirectToAction("SessionTimeOut", "User");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return View(peoplecreate);
            }
        }
        public ActionResult Edit(string id = "", string peopleguid = "")
        {
            Logger.Debug("Inside People Controller- Create");
            try
            {

                if (Session["OrganizationGUID"] != null)
                {
                    TempData["TabName"] = "Contacts";
                    Person EditPeople = _IPeopleRepository.GetPeopleByID(new Guid(peopleguid));
                    PeopleModel people = new PeopleModel();
                    if (EditPeople != null)
                    {
                        ViewBag.ContactName = EditPeople.FirstName;
                        people.PeopleGUID = EditPeople.PeopleGUID.ToString();
                        people.UserGUID = EditPeople.UserGUID.ToString();
                        people.OrganizationGUID = EditPeople.OrganizationGUID != null ? EditPeople.OrganizationGUID.ToString() : Guid.Empty.ToString();
                        people.IsPrimaryContact = Convert.ToBoolean(EditPeople.IsPrimaryContact);
                        people.PlaceGUID = EditPeople.PlaceGUID != null ? EditPeople.PlaceGUID.ToString() : Guid.Empty.ToString();
                        people.FirstName = EditPeople.FirstName;

                        people.LastName = EditPeople.LastName;
                        people.MobilePhone = EditPeople.MobilePhone;
                        people.CompanyName = EditPeople.CompanyName;
                        people.BusinessPhone = EditPeople.BusinessPhone;
                        people.HomePhone = EditPeople.HomePhone;
                        people.Emails = EditPeople.Emails;
                        people.AddressLine1 = EditPeople.AddressLine1;
                        people.AddressLine2 = EditPeople.AddressLine2;
                        people.City = EditPeople.City;
                        people.State = EditPeople.State;
                        people.Country = EditPeople.Country;
                        people.ZipCode = EditPeople.ZipCode;

                    }
                    var userList = new AspNetUserViewModel();
                    userList.Users = new List<AspUser>();
                    var appUser = _IUserProfileRepository.GetUserProfilesbyOrganizationGUID(new Guid(Session["OrganizationGUID"].ToString())).OrderBy(sort => sort.FirstName).ToList();
                    //if (string.IsNullOrEmpty(id))
                    {
                        userList.Users.Add(new AspUser { FirstName = "All", LastName = "", UserGUID = Guid.Empty.ToString(), OrganizationGUID = "" });
                        foreach (var user in appUser.ToList())
                        {
                            userList.Users.Add(new AspUser { FirstName = user.FirstName, LastName = user.LastName, UserGUID = user.UserGUID.ToString() });
                        }
                    }

                    var placeList = new PlaceViewModel();
                    placeList.PlaceList = new List<PlaceModel>();
                    var appPlace = new List<Place>();
                    if (string.IsNullOrEmpty(id) || Guid.Empty == new Guid(id))
                    {
                        appPlace = _IPlaceRepository.GetPlaceByOrganizationGUID(new Guid(Session["OrganizationGUID"].ToString())).ToList();
                        if (!string.IsNullOrEmpty(id) && Guid.Empty == new Guid(id))
                            ViewBag.UserID = Guid.Empty.ToString();
                    }
                    else
                    {
                        appPlace = _IPlaceRepository.GetPlaceByUserGUID(new Guid(id)).ToList();
                        ViewBag.UserID = id;
                    }
                    foreach (var place in appPlace.ToList())
                    {
                        placeList.PlaceList.Add(new PlaceModel
                        {
                            PlaceGUID = place.PlaceGUID.ToString(),
                            PlaceID = place.PlaceID,
                            PlaceName = place.PlaceName,
                            PlacePhone = place.PlacePhone,
                            FirstName = place.FirstName,
                            LastName = place.LastName,
                            UserGUID = place.UserGUID.ToString(),
                            OrganizationGUID = place.OrganizationGUID != null ? place.OrganizationGUID.ToString() : Guid.Empty.ToString(),
                            MobilePhone = place.MobilePhone,
                            HomePhone = place.HomePhone,
                            Emails = place.Emails,
                            TimeZone = place.TimeZone,
                            AddressLine1 = place.AddressLine1,
                            AddressLine2 = place.AddressLine2,
                            City = place.City,
                            State = place.State,
                            Country = place.Country,
                            ZipCode = place.ZipCode

                        });
                    }
                    var placeviewModel = new PlaceViewModel();
                    placeviewModel.Place = placeList.PlaceList.AsEnumerable();
                    placeviewModel.User = userList.Users.AsEnumerable();

                    var PeopleViewForCreate = new PeopleViewForCreate();
                    PeopleViewForCreate.PlaceViewModel = placeviewModel;
                    PeopleViewForCreate.PeopleModel = people;
                    return View(PeopleViewForCreate);

                }
                else
                {
                    return RedirectToAction("SessionTimeOut", "User");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return RedirectToAction("Login", "User");
            }
        }