public ActionResult EditCustomer(customerview pcustomerview)
        {
            Logger.Debug("Inside Place Controller- Edit Http Post");
            try
            {
                if (Session["OrganizationGUID"] != null)
                {
                    if (ModelState.IsValid)
                    {
                        if (pcustomerview.PlaceModel != null)
                        {
                            Place Place = new Place();
                            Place.PlaceGUID = new Guid(pcustomerview.PlaceModel.PlaceGUID);
                            Place.UserGUID = new Guid(pcustomerview.PlaceModel.UserGUID);
                            Place.PlaceID = pcustomerview.PlaceModel.PlaceID;
                            Place.OrganizationGUID = !string.IsNullOrEmpty(pcustomerview.PlaceModel.OrganizationGUID) ? new Guid(pcustomerview.PlaceModel.OrganizationGUID) : Guid.Empty;
                            Place.PlaceName = pcustomerview.PlaceModel.PlaceName;
                            Place.FirstName = pcustomerview.PlaceModel.FirstName;
                            Place.LastName = pcustomerview.PlaceModel.LastName;
                            Place.MobilePhone = pcustomerview.PlaceModel.MobilePhone;
                            Place.PlacePhone = pcustomerview.PlaceModel.PlacePhone;
                            Place.HomePhone = pcustomerview.PlaceModel.HomePhone;
                            Place.Emails = pcustomerview.PlaceModel.Emails;
                            Place.AddressLine1 = pcustomerview.PlaceModel.AddressLine1;
                            Place.AddressLine2 = pcustomerview.PlaceModel.AddressLine2;
                            Place.City = pcustomerview.PlaceModel.City;
                            Place.State = pcustomerview.PlaceModel.State;
                            Place.Country = pcustomerview.PlaceModel.Country;
                            Place.ZipCode = pcustomerview.PlaceModel.ZipCode;
                            Place.UpdatedDate = DateTime.UtcNow;
                            LatLong latLong = new LatLong();
                            latLong = GetLatLngCode(Place.AddressLine1, Place.AddressLine2, Place.City, Place.State, Place.Country, Place.ZipCode);
                            Place.TimeZone = getTimeZone(latLong.Latitude, latLong.Longitude).ToString();

                            int placeInsertResult = _IPlaceRepository.UpdatePlace(Place);
                            // int placeInsertResult = _IPlaceRepository.Save();
                            if (placeInsertResult > 0)
                            {
                                //return RedirectToAction("Index", "CustomerView", new { id = "Details", customerid = Place.PlaceGUID.ToString() });
                                return RedirectToAction("Index", "Place");
                            }
                            else
                            {
                                TempData["TabName"] = "Details";
                                pcustomerview.PeopleViewModel = ContactDetails(pcustomerview.PlaceModel.PlaceGUID);
                                pcustomerview.MarketViewModel = CustomerStopDetails(pcustomerview.PlaceModel.PlaceGUID);
                            }
                        }
                    }
                    else
                    {
                        TempData["TabName"] = "Details";
                        pcustomerview.PeopleViewModel = ContactDetails(pcustomerview.PlaceModel.PlaceGUID);
                        pcustomerview.MarketViewModel = CustomerStopDetails(pcustomerview.PlaceModel.PlaceGUID);

                    }
                    return View("Index", pcustomerview);
                }
                else
                {
                    return RedirectToAction("SessionTimeOut", "User");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return View(pcustomerview);
            }
        }
        //
        // GET: /CustomerView/
        public ActionResult Index(string id = "", string customerid = "", string regionguid = "", string selection = "", string Contact_RowCount = "", string Store_RowCount = "", int page = 1, string Contact_Search = "", string Store_Search = "")
        {
            Logger.Debug("Inside CustomerView Controller- Index");
            try
            {
                ViewBag.CustomerID = customerid;
                ViewBag.RegionGUID = regionguid;
                int contact_TotalPage = 0;
                int contact_TotalRecord = 0;
                int contact_pCount = 0;

                int store_TotalPage = 0;
                int store_TotalRecord = 0;
                int store_pCount = 0;

                if (Session["OrganizationGUID"] != null)
                {
                    if (!string.IsNullOrEmpty(Contact_RowCount))
                    {
                        int.TryParse(Contact_RowCount, out contact_pCount);
                        pageContactCountList(contact_pCount);

                    }
                    else
                    {
                        pageContactCountList(contact_pCount);
                    }
                    if (!string.IsNullOrEmpty(Store_RowCount))
                    {
                        int.TryParse(Store_RowCount, out store_pCount);
                        pageStoreCountList(store_pCount);

                    }
                    else
                    {
                        pageStoreCountList(store_pCount);
                    }


                    customerview pcustomerview = new customerview();
                    pcustomerview.PeopleViewModel = new PeopleViewModel();
                    pcustomerview.MarketViewModel = new MarketViewModel();
                    pcustomerview.PlaceModel = new PlaceModel();


                    if (!string.IsNullOrEmpty(customerid))
                    {
                        ViewBag.CustomerID = customerid;
                        StringBuilder sb = new StringBuilder();
                        sb.Append("<div class='actions'>");
                        sb.Append("<div class='btn-group'>");
                        if (!string.IsNullOrEmpty(regionguid))
                        {
                            sb.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i> " + _IRegionRepository.GetRegionNameByRegionGUID(new Guid(regionguid)) + " <i class='icon-angle-down'></i></a>");
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(selection) && selection == "All")
                            {
                                sb.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i> All <i class='icon-angle-down'></i></a>");
                            }
                            else
                            {
                                sb.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i> Select Region <i class='icon-angle-down'></i></a>");
                            }
                        }
                        sb.Append("<ul id='ulworkgroup' style='height:100px;overflow-y:scroll' class='dropdown-menu pull-right'>");
                        if (string.IsNullOrEmpty(selection) || selection != "All")
                        {
                            //sb.Append("<li><a href=" + Url.Action("Index", "CustomerView", new { id = "Stores", customerid = customerid, selection = "All" }) + ">All</a></li>");
                            sb.Append("<li><a onclick=\"RedirectAction('Stores','');\">All</a></li>");
                        }
                        List<Region> RegionList = _IRegionRepository.GetRegionByOrganizationGUID(new Guid(Session["OrganizationGUID"].ToString())).ToList();
                        foreach (Region item in RegionList)
                        {
                            //sb.Append("<li><a href=" + Url.Action("Index", "CustomerView", new { id = "Stores", customerid = customerid, regionguid = item.RegionGUID.ToString() }) + " data-groupguid=" + item.RegionGUID + ">" + item.Name + "</a></li>");
                            sb.Append("<li><a onclick=\"RedirectAction('Stores','" + item.RegionGUID + "','" + customerid + "');\" data-groupguid=" + item.RegionGUID + ">" + item.Name + "</a></li>");
                        }
                        sb.Append("</ul>");
                        sb.Append("</div>");
                        sb.Append("</div>");
                        ViewBag.RegionList = sb.ToString();

                        Session["CustomerGUID"] = customerid;
                        if (!string.IsNullOrEmpty(id))
                        {
                            TempData["TabName"] = id;
                        }
                        else
                        {
                            TempData["TabName"] = "Details";
                        }
                        #region Contact Details

                        var peopleList = new PeopleViewModel();
                        peopleList.PeopleList = new List<PeopleModel>();
                        var appPeople = new List<Person>();

                        appPeople = _IPeopleRepository.GetPeopleByPlaceGUID(new Guid(customerid)).ToList();
                        ViewBag.PlaceGUID = customerid;

                        if (appPeople != null && appPeople.Count > 0)
                        {
                            ViewBag.Contact_Search = Contact_Search;
                            if (!string.IsNullOrEmpty(Contact_Search))
                            {
                                Contact_Search = Contact_Search.ToLower();
                                appPeople = appPeople.Where(
                                    p => (!String.IsNullOrEmpty(p.FirstName) && p.FirstName.ToLower().StartsWith(Contact_Search))
                                || (!String.IsNullOrEmpty(p.BusinessPhone) && p.BusinessPhone.ToLower().StartsWith(Contact_Search))
                                || (!String.IsNullOrEmpty(p.MobilePhone) && p.MobilePhone.ToLower().StartsWith(Contact_Search))
                                || (!String.IsNullOrEmpty(p.Emails) && p.Emails.ToLower().StartsWith(Contact_Search))).ToList();
                            }



                            contact_TotalRecord = appPeople.ToList().Count;
                            contact_TotalPage = (contact_TotalRecord / (int)ViewBag.pageContactCountValue) + ((contact_TotalRecord % (int)ViewBag.pageContactCountValue) > 0 ? 1 : 0);

                            ViewBag.Contact_TotalRows = contact_TotalRecord;
                            appPeople = appPeople.OrderBy(a => a.OrganizationGUID).Skip(((page - 1) * (int)ViewBag.pageContactCountValue)).Take((int)ViewBag.pageContactCountValue).ToList();

                            foreach (var people in appPeople.ToList())
                            {
                                peopleList.PeopleList.Add(new PeopleModel
                                {
                                    PeopleGUID = people.PeopleGUID.ToString(),
                                    PlaceGUID = people.PlaceGUID.ToString(),
                                    CompanyName = people.CompanyName,
                                    BusinessPhone = people.BusinessPhone,
                                    MarketGUID = people.MarketGUID.ToString(),
                                    FirstName = people.FirstName,
                                    LastName = people.LastName,
                                    UserGUID = people.UserGUID.ToString(),
                                    OrganizationGUID = people.OrganizationGUID.ToString(),
                                    MobilePhone = people.MobilePhone,
                                    HomePhone = people.HomePhone,
                                    Emails = people.Emails,
                                    AddressLine1 = people.AddressLine1,
                                    AddressLine2 = people.AddressLine2,
                                    City = people.City,
                                    State = people.State,
                                    Country = people.Country,
                                    ZipCode = people.ZipCode,
                                    StoreID = getStoreID(people.PeopleGUID.ToString())

                                });
                            }
                        }

                        var viewModel = new PeopleViewModel();
                        // viewModel.Place = placeList.PlaceList.AsEnumerable();
                        viewModel.People = peopleList.PeopleList.AsEnumerable();
                        pcustomerview.PeopleViewModel = viewModel;
                        #endregion

                        #region Customer Stop Details

                        var marketList = new MarketViewModel();
                        marketList.MarketList = new List<MarketModel>();
                        var appMarket = new List<Market>();
                        if (!string.IsNullOrEmpty(regionguid))
                        {
                            TempData["TabName"] = "Stores";
                            appMarket = _IMarketRepository.GetMarketByOwnerandRegionGUID(new Guid(regionguid), new Guid(customerid), 1).ToList();
                        }
                        else
                        {
                            appMarket = _IMarketRepository.GetMarketByOwnerGUID(new Guid(customerid)).ToList();
                        }

                        if (appMarket != null && appMarket.Count > 0)
                        {
                            ViewBag.Store_Search = Store_Search;
                            if (!string.IsNullOrEmpty(Store_Search))
                            {
                                Store_Search = Store_Search.ToLower();
                                appMarket = appMarket.Where(
                                    p => (!String.IsNullOrEmpty(p.MarketName) && p.MarketName.ToLower().StartsWith(Store_Search))
                                || (!String.IsNullOrEmpty(p.MarketID) && p.MarketID.ToLower().StartsWith(Store_Search))
                                || (!String.IsNullOrEmpty(_IUserProfileRepository.GetUserProfileByUserID(new Guid(p.UserGUID.ToString()), new Guid(p.OrganizationGUID.ToString())).FirstName) && (_IUserProfileRepository.GetUserProfileByUserID(new Guid(p.UserGUID.ToString()), new Guid(p.OrganizationGUID.ToString())).FirstName).ToLower().Contains(Store_Search))
                                || (!String.IsNullOrEmpty(p.MarketPhone) && p.MarketPhone.ToLower().StartsWith(Store_Search))
                                || (!String.IsNullOrEmpty(p.Emails) && p.Emails.ToLower().StartsWith(Store_Search))).ToList();
                            }

                            store_TotalRecord = appMarket.ToList().Count;
                            store_TotalPage = (store_TotalRecord / (int)ViewBag.pageStoreCountValue) + ((store_TotalRecord % (int)ViewBag.pageStoreCountValue) > 0 ? 1 : 0);

                            ViewBag.Store_TotalRows = store_TotalRecord;
                            appMarket = appMarket.OrderBy(a => a.OrganizationGUID).Skip(((page - 1) * (int)ViewBag.pageStoreCountValue)).Take((int)ViewBag.pageStoreCountValue).ToList();

                            foreach (var market in appMarket.ToList())
                            {
                                MarketModel MarketModel = new MarketModel();

                                MarketModel.MarketID = market.MarketID;
                                MarketModel.MarketGUID = market.MarketGUID.ToString();
                                MarketModel.UserGUID = market.UserGUID != null ? market.UserGUID.ToString() : Guid.Empty.ToString();
                                MarketModel.OrganizationGUID = market.OrganizationGUID != null ? market.OrganizationGUID.ToString() : Guid.Empty.ToString();
                                MarketModel.OwnerGUID = market.OwnerGUID != null ? market.OwnerGUID.ToString() : Guid.Empty.ToString();
                                MarketModel.MarketName = market.MarketName;
                                MarketModel.MarketPhone = market.MarketPhone;
                                MarketModel.PrimaryContactGUID = market.PrimaryContactGUID != null ? market.PrimaryContactGUID.ToString() : Guid.Empty.ToString();
                                MarketModel.FirstName = market.FirstName;

                                if (!string.IsNullOrEmpty(market.RMUserID))
                                {
                                    GlobalUser _globalUser = _IGlobalUserRepository.GetGlobalUserByUserID(market.RMUserID, Session["OrganizationGUID"].ToString());
                                    if (_globalUser != null)
                                    {
                                        UserProfile _userprofile = _IUserProfileRepository.GetUserProfileByUserID(_globalUser.UserGUID, new Guid(MarketModel.OrganizationGUID));
                                        if (_userprofile != null)
                                        {
                                            MarketModel.RMName = _userprofile.FirstName + " " + _userprofile.LastName;
                                        }
                                        else
                                        {
                                            MarketModel.RMName = "";
                                        }
                                    }

                                }
                                MarketModel.LastName = market.LastName;
                                MarketModel.MobilePhone = market.MobilePhone;
                                MarketModel.HomePhone = market.HomePhone;
                                MarketModel.Emails = market.Emails;
                                MarketModel.AddressLine1 = market.AddressLine1;
                                MarketModel.AddressLine2 = market.AddressLine2;
                                MarketModel.City = market.City;
                                MarketModel.State = market.State;
                                MarketModel.Country = market.Country;
                                MarketModel.ZipCode = market.ZipCode;
                                MarketModel.RegionGUID = market.RegionGUID != null ? market.RegionGUID.ToString() : Guid.Empty.ToString();
                                MarketModel.TerritoryGUID = market.TerritoryGUID != null ? market.TerritoryGUID.ToString() : Guid.Empty.ToString();
                                MarketModel.RegionName = market.RegionGUID != null ? _IRegionRepository.GetRegionNameByRegionGUID(new Guid(market.RegionGUID.ToString())) : "";
                                MarketModel.TerritoryName = market.TerritoryGUID != null ? _ITerritoryRepository.GetTerritoryNameByTerritoryGUID(new Guid(market.TerritoryGUID.ToString())) : "";
                                marketList.MarketList.Add(MarketModel);
                            }
                        }

                        var mviewModel = new MarketViewModel();
                        //  mviewModel.Place = placeList.PlaceList.AsEnumerable();
                        mviewModel.Market = marketList.MarketList.AsEnumerable();
                        pcustomerview.MarketViewModel = mviewModel;
                        #endregion

                        #region Customer Edit
                        PlaceModel lplace = new PlaceModel();
                        lplace.PlaceGUID = customerid;
                        Place Place = _IPlaceRepository.GetPlaceByID(new Guid(lplace.PlaceGUID));
                        if (Place != null)
                        {
                            lplace.PlaceGUID = Place.PlaceGUID.ToString();
                            lplace.PlaceID = Place.PlaceID;
                            lplace.UserGUID = Place.UserGUID.ToString();
                            lplace.OrganizationGUID = Place.OrganizationGUID != null ? Place.OrganizationGUID.ToString() : Guid.Empty.ToString();
                            lplace.PlaceName = Place.PlaceName;
                            lplace.FirstName = Place.FirstName;
                            lplace.LastName = Place.LastName;
                            lplace.MobilePhone = Place.MobilePhone;
                            lplace.PlacePhone = Place.PlacePhone;
                            lplace.HomePhone = Place.HomePhone;
                            lplace.Emails = Place.Emails;
                            lplace.AddressLine1 = Place.AddressLine1;
                            lplace.AddressLine2 = Place.AddressLine2;
                            lplace.City = Place.City;
                            lplace.State = Place.State;
                            lplace.Country = Place.Country;
                            lplace.ZipCode = Place.ZipCode;
                            Session["PlaceName"] = Place.PlaceName;
                            pcustomerview.PlaceModel = lplace;
                            ViewBag.ClientID = lplace.PlaceGUID.ToString();
                            //UserProfile _userProfile = _IUserProfileRepository.GetUserProfileByUserID(Place.UserGUID);
                            //if (_userProfile != null)
                            //{
                            //    pcustomerview.ManagerName = _userProfile.FirstName + " " + _userProfile.LastName;
                            //}
                            //else
                            //{
                            //    pcustomerview.ManagerName = "";
                            //}

                        }
                        #endregion

                        if (!string.IsNullOrEmpty(Contact_RowCount))
                            ViewBag.pageContactCountValue = int.Parse(Contact_RowCount);
                        else
                            ViewBag.pageContactCountValue = 5;
                        if (!string.IsNullOrEmpty(Store_RowCount))
                            ViewBag.pageStoreCountValue = int.Parse(Store_RowCount);
                        else
                            ViewBag.pageStoreCountValue = 5;
                        bool contact = false;
                        bool store = false;
                        if (null != Request && System.Text.RegularExpressions.Regex.IsMatch(Request.Url.ToString(), string.Format(@"\b{0}\b", "Contacts")))
                            contact = true;
                        if (null != Request && System.Text.RegularExpressions.Regex.IsMatch(Request.Url.ToString(), string.Format(@"\b{0}\b", "Stores")))
                            store = true;

                        if (contact)
                            TempData["TabName"] = "Contacts";
                        else if (store)
                            TempData["TabName"] = "Stores";
                    }
                    return View(pcustomerview);
                }
                else
                {
                    return RedirectToAction("SessionTimeOut", "User");
                }

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