private MarketModel ConvertToStoreNonVisit(Market market)
        {
            try
            {
                MarketModel _market = new MarketModel();
                _market.MarketID = market.MarketID;
                _market.MarketGUID = market.MarketGUID.ToString();
                _market.UserGUID = market.UserGUID != null ? market.UserGUID.ToString() : Guid.Empty.ToString();
                _market.OrganizationGUID = market.OrganizationGUID != null ? market.OrganizationGUID.ToString() : Guid.Empty.ToString();
                _market.OwnerGUID = market.OwnerGUID != null ? market.OwnerGUID.ToString() : Guid.Empty.ToString();
                _market.MarketName = market.MarketName;
                _market.MarketPhone = market.MarketPhone;
                _market.PrimaryContactGUID = market.PrimaryContactGUID != null ? market.PrimaryContactGUID.ToString() : Guid.Empty.ToString();
                if (!string.IsNullOrEmpty(market.RMUserID))
                {
                    GlobalUser _globalUser = _IGlobalUserRepository.GetGlobalUserByUserID(market.RMUserID, _market.OrganizationGUID);
                    if (_globalUser != null)
                    {
                        UserProfile _userprofile = _IUserProfileRepository.GetUserProfileByUserID(_globalUser.UserGUID, new Guid(_market.OrganizationGUID));
                        if (_userprofile != null)
                        {
                            _market.RMName = _userprofile.FirstName + " " + _userprofile.LastName;
                        }
                        else
                        {
                            _market.RMName = "";
                        }
                    }

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

                }
                else
                {
                    _market.FMName = "";
                }
                _market.FirstName = market.FirstName;
                _market.LastName = market.LastName;
                _market.MobilePhone = market.MobilePhone;
                _market.HomePhone = market.HomePhone;
                _market.Emails = market.Emails;
                _market.AddressLine1 = market.AddressLine1;
                _market.AddressLine2 = market.AddressLine2;
                _market.City = market.City;
                _market.State = market.State;
                _market.Country = market.Country;
                _market.ZipCode = market.ZipCode;
                _market.RegionGUID = market.RegionGUID != null ? market.RegionGUID.ToString() : Guid.Empty.ToString();
                _market.TerritoryGUID = market.TerritoryGUID != null ? market.TerritoryGUID.ToString() : Guid.Empty.ToString();
                _market.RegionName = market.RegionGUID != null ? _IRegionRepository.GetRegionNameByRegionGUID(new Guid(market.RegionGUID.ToString())) : "";
                _market.TerritoryName = market.TerritoryGUID != null ? _ITerritoryRepository.GetTerritoryNameByTerritoryGUID(new Guid(market.TerritoryGUID.ToString())) : "";
                _market.LastStoreVisitedDate = market.LastStoreVisitedDate != null ? Session["TimeZoneID"] != null ? _IUserRepository.GetLocalDateTime(market.LastStoreVisitedDate, Session["TimeZoneID"].ToString()) : market.LastStoreVisitedDate.ToString() : "";

                return _market;
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return null;
            }


        }
        public ActionResult Create(OrganizationView organization)
        {
            Logger.Debug("Inside Organization Controller- Create HttpPost");
            try
            {
                if (ModelState.IsValid)
                {
                    if (_IOrganizationRepository.GetOrganizationByID(organization.OrganizationGUID) == null)
                    {
                        Organization Organization = new Organization();
                        Organization.OrganizationFullName = organization.OrganizationFullName;
                        Organization.OrganizationName = organization.OrganizationFullName.Trim();
                        Organization.OrganizationGUID = Guid.NewGuid();
                        Organization.Website = organization.Website;
                        Organization.Phone = organization.Phone;
                        Organization.AddressLine1 = organization.AddressLine1;
                        Organization.AddressLine2 = organization.AddressLine2;
                        Organization.City = organization.City;
                        Organization.Country = organization.Country;
                        Organization.ZipCode = organization.ZipCode;
                        LatLong latLong = new LatLong();
                        latLong = GetLatLngCode(Organization.AddressLine1, Organization.AddressLine2, Organization.City, Organization.State, Organization.Country, Organization.ZipCode);
                        Organization.TimeZone = Convert.ToDouble(getTimeZone(latLong.Latitude, latLong.Longitude));
                        Organization.Latitude = latLong.Latitude;
                        Organization.Longitude = latLong.Longitude;
                        Organization.EmailID = organization.EmailID;
                        Organization.State = organization.State;
                        Organization.IsActive = false;
                        Organization.IsDeleted = false;
                        Organization.AllowContractors = true;
                        Organization.ImageURL = organization.ImageURL;
                        Organization.CreateDate = DateTime.UtcNow;
                        if (Session["UserGUID"] != null)
                            Organization.CreateBy = new Guid(Session["UserGUID"].ToString());
                        Organization.LastModifiedDate = DateTime.UtcNow;
                        if (Session["UserGUID"] != null)
                            Organization.LastModifiedBy = new Guid(Session["UserGUID"].ToString());
                        //Group Group = new Group();
                        //Group.GroupGUID = Guid.NewGuid();
                        //Group.Name = "Default";
                        //Group.Description = "Default";
                        //Group.OrganizationGUID = Organization.OrganizationGUID;
                        //Group.IsDefault = false;

                        Region Region = new Region();
                        Region.RegionGUID = Guid.NewGuid();
                        Region.Name = "Default";
                        Region.Description = "Default";
                        if (Organization.OrganizationGUID != Guid.Empty)
                        {
                            Region.OrganizationGUID = Organization.OrganizationGUID;
                        }
                        else
                        {
                            Region.OrganizationGUID = null;
                        }
                        Region.IsDefault = false;

                        Territory Territory = new Territory();
                        Territory.TerritoryGUID = Guid.NewGuid();
                        if (Territory.RegionGUID != Guid.Empty)
                        {
                            Territory.RegionGUID = Territory.RegionGUID;
                        }
                        else
                        {
                            Territory.RegionGUID = null;
                        }
                        Territory.Name = "Default";
                        Territory.Description = "Default";
                        if (Organization.OrganizationGUID != Guid.Empty)
                        {
                            Territory.OrganizationGUID = Organization.OrganizationGUID;
                        }
                        else
                        {
                            Territory.OrganizationGUID = null;
                        }
                        Territory.IsDefault = false;




                        GlobalUser globalUser = new GlobalUser();
                        globalUser.UserGUID = Guid.NewGuid();
                        globalUser.USERID = organization.UserID;
                        globalUser.UserName = organization.UserName;
                        globalUser.Password = _IUserRepository.EncodeTo64(organization.Password);
                        globalUser.IsActive = true;
                        globalUser.IsDelete = false;
                        globalUser.Latitude = latLong.Latitude;
                        globalUser.Longitude = latLong.Longitude;
                        globalUser.Role_Id = _IGlobalUserRepository.GetOrganizationAdminRoleID();
                        globalUser.CreateDate = DateTime.UtcNow;
                        if (Session["UserGUID"] != null)
                            globalUser.CreateBy = new Guid(Session["UserGUID"].ToString());
                        globalUser.LastModifiedDate = DateTime.UtcNow;
                        if (Session["UserGUID"] != null)
                            globalUser.LastModifiedBy = new Guid(Session["UserGUID"].ToString());

                        UserProfile userprofile = new UserProfile();
                        userprofile.ProfileGUID = Guid.NewGuid();
                        userprofile.UserGUID = globalUser.UserGUID;
                        userprofile.CompanyName = Organization.OrganizationFullName;
                        userprofile.FirstName = organization.FirstName;
                        userprofile.LastName = organization.LastName;
                        userprofile.MobilePhone = "";
                        userprofile.BusinessPhone = organization.Phone;
                        userprofile.HomePhone = "";
                        userprofile.EmailID = organization.EmailID;
                        userprofile.AddressLine1 = organization.AddressLine1;
                        userprofile.AddressLine2 = organization.AddressLine2;
                        userprofile.City = organization.City;
                        userprofile.State = organization.State;
                        userprofile.Country = organization.Country;
                        userprofile.Latitude = latLong.Latitude;
                        userprofile.Longitude = latLong.Longitude;
                        userprofile.ZipCode = organization.ZipCode;
                        userprofile.IsDeleted = false;
                        userprofile.PicFileURL = Organization.ImageURL;
                        userprofile.LastModifiedDate = DateTime.UtcNow;
                        if (Session["UserGUID"] != null)
                            userprofile.LastModifiedBy = new Guid(Session["UserGUID"].ToString());


                        userprofile.CompanyName = Organization.OrganizationName;

                        AspNetUser aspnetuser = new AspNetUser();
                        aspnetuser.Id = globalUser.UserGUID.ToString();
                        aspnetuser.UserName = organization.UserName;
                        aspnetuser.FirstName = organization.FirstName;
                        aspnetuser.LastName = organization.LastName;
                        aspnetuser.PasswordHash = _IUserRepository.EncodeTo64(organization.Password);
                        aspnetuser.PhoneNumber = organization.Phone;
                        aspnetuser.EmailID = organization.EmailID;
                        if (Organization.OrganizationGUID != Guid.Empty)
                        {
                            aspnetuser.OrganizationGUID = Organization.OrganizationGUID;
                        }
                        else
                        {
                            aspnetuser.OrganizationGUID = null;
                        }
                        aspnetuser.SecurityStamp = "";
                        aspnetuser.Discriminator = "";

                        OrganizationSubscription organizationSubscription = new OrganizationSubscription();
                        organizationSubscription.OrganizationSubscriptionGUID = Guid.NewGuid();
                        organizationSubscription.OrganizationGUID = Organization.OrganizationGUID;
                        organizationSubscription.IsActive = true;
                        organizationSubscription.Version = 1;
                        organizationSubscription.SubscriptionPurchased = 100;
                        organizationSubscription.SubscriptionConsumed = 1;
                        organizationSubscription.StartDate = DateTime.UtcNow;
                        organizationSubscription.ExpiryDate = DateTime.UtcNow.AddDays(30);
                        organizationSubscription.CreatedDate = DateTime.UtcNow;


                        UserSubscription userSubscription = new UserSubscription();
                        userSubscription.UserSubscriptionGUID = Guid.NewGuid();
                        userSubscription.UserGUID = globalUser.UserGUID;
                        if (organizationSubscription.OrganizationSubscriptionGUID != Guid.Empty)
                        {
                            userSubscription.OrganizationSubscriptionGUID = organizationSubscription.OrganizationSubscriptionGUID;
                        }
                        else
                        {
                            userSubscription.OrganizationSubscriptionGUID = null;
                        }

                        userSubscription.IsActive = true;
                        userSubscription.CreatedDate = DateTime.UtcNow;

                        Market Market = new Market();
                        Market.MarketGUID = Guid.NewGuid();
                        Market.IsDefault = true;
                        if (globalUser.UserGUID != Guid.Empty)
                        {
                            Market.UserGUID = globalUser.UserGUID;
                        }
                        else
                        {
                            Market.UserGUID = null;
                        }
                        Market.EntityType = 0;
                        if (Organization.OrganizationGUID != Guid.Empty)
                        {
                            Market.OrganizationGUID = Organization.OrganizationGUID;
                        }
                        else
                        {
                            Market.OrganizationGUID = null;
                        }
                        if (Organization.OrganizationGUID != Guid.Empty)
                        {
                            Market.OwnerGUID = Organization.OrganizationGUID;
                        }
                        else
                        {
                            Market.OwnerGUID = null;
                        }
                        Market.MarketName = Organization.OrganizationFullName;
                        if (Region.RegionGUID != Guid.Empty)
                        {
                            Market.RegionGUID = Region.RegionGUID;
                        }
                        else
                        {
                            Market.RegionGUID = null;
                        }
                        if (Territory.TerritoryGUID != Guid.Empty)
                        {
                            Market.TerritoryGUID = Territory.TerritoryGUID;
                        }
                        else
                        {
                            Market.TerritoryGUID = null;
                        }
                        if (globalUser.UserGUID != Guid.Empty)
                        {
                            Market.PrimaryContactGUID = globalUser.UserGUID;
                        }
                        else
                        {
                            Market.PrimaryContactGUID = null;
                        }
                        Market.FirstName = organization.FirstName;
                        Market.LastName = organization.LastName;
                        Market.MobilePhone = "";
                        Market.MarketPhone = organization.Phone;
                        Market.HomePhone = "";
                        Market.Emails = organization.EmailID;
                        Market.TimeZone = Organization.TimeZone.ToString();
                        Market.AddressLine1 = organization.AddressLine1;
                        Market.AddressLine2 = organization.AddressLine2;
                        Market.City = organization.City;
                        Market.State = organization.State;
                        Market.Country = organization.Country;
                        Market.ZipCode = organization.ZipCode;
                        Market.Latitude = latLong.Latitude;
                        Market.Longitude = latLong.Longitude;
                        Market.ImageURL = organization.ImageURL;
                        Market.IsDeleted = false;
                        Market.CreateDate = DateTime.UtcNow;
                        Market.UpdatedDate = DateTime.UtcNow;

                        OrganizationUsersMap organizationUserMap = new OrganizationUsersMap();
                        organizationUserMap.OrganizationUserMapGUID = Guid.NewGuid();
                        organizationUserMap.OrganizationGUID = Organization.OrganizationGUID;
                        organizationUserMap.UserGUID = globalUser.UserGUID;
                        organizationUserMap.IsContractor = false;
                        organizationUserMap.IsActive = true;
                        organizationUserMap.Status = 0;
                        if (Region.RegionGUID != Guid.Empty)
                        {
                            organizationUserMap.RegionGUID = Region.RegionGUID;
                        }
                        else
                        {
                            organizationUserMap.RegionGUID = null;
                        }
                        if (Territory.TerritoryGUID != Guid.Empty)
                        {
                            organizationUserMap.TerritoryGUID = Territory.TerritoryGUID;
                        }
                        else
                        {
                            organizationUserMap.TerritoryGUID = null;
                        }
                        organizationUserMap.UserType = "ENT_A";
                        organizationUserMap.CreateDate = DateTime.UtcNow;
                        if (Session["UserGUID"] != null)
                            organizationUserMap.CreateBy = new Guid(Session["UserGUID"].ToString());
                        organizationUserMap.LastModifiedDate = DateTime.UtcNow;
                        if (Session["UserGUID"] != null)
                            organizationUserMap.LastModifiedBy = new Guid(Session["UserGUID"].ToString());



                        int result = _IOrganizationRepository.InsertOrganization(Organization);
                        // int result = _IOrganizationRepository.Save();
                        if (result > 0)
                        {
                            _IOrganizationSubscriptionRepository.InsertOrganizationSubscription(organizationSubscription);
                            //_IOrganizationSubscriptionRepository.Save();
                            //_IGroupRepository.InsertGroup(Group);
                            //_IGroupRepository.Save();
                            _IRegionRepository.InsertRegion(Region);
                            //_IRegionRepository.Save();
                            _ITerritoryRepository.InsertTerritory(Territory);
                            // _ITerritoryRepository.Save();

                            int userresult = _IUserRepository.InsertUser(aspnetuser);
                            // int userresult = _IUserRepository.Save();
                            if (userresult > 0)
                            {
                                int guresult = _IGlobalUserRepository.InsertGlobalUser(globalUser);
                                //int guresult = _IGlobalUserRepository.Save();

                                if (guresult > 0)
                                {
                                    int OrgUserMap = _IOrganizationRepository.InsertOrganizationUserMap(organizationUserMap);
                                    //int OrgUserMap = _IOrganizationRepository.Save();
                                    if (OrgUserMap > 0)
                                    {
                                        int usrresult = _IUserProfileRepository.InsertUserProfile(userprofile);
                                        //int usrresult = _IUserProfileRepository.Save();
                                        if (usrresult > 0)
                                        {
                                            int usubresult = _IUserSubscriptionRepository.InsertUserSubscription(userSubscription);
                                            //int usubresult = _IUserSubscriptionRepository.Save();
                                            if (usubresult > 0)
                                            {
                                                int marketresult = _IMarketRepository.InsertMarket(Market);
                                                //int marketresult = _IMarketRepository.Save();
                                                if (marketresult > 0)
                                                {
                                                    if (Session["UserType"] != null && Session["UserType"].ToString() == "WIM_A")
                                                    {
                                                        TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','Organization Created Successfully');</script>";
                                                        return RedirectToAction("Index", "Organization");
                                                    }
                                                    else
                                                    {
                                                        TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','Organization Created Successfully');</script>";
                                                        return RedirectToAction("../User/Login");
                                                    }
                                                }
                                                else
                                                {
                                                    _IUserSubscriptionRepository.DeleteUserSubscription(userSubscription.UserSubscriptionGUID);
                                                    //_IUserSubscriptionRepository.Save();
                                                    //_IGroupRepository.DeleteGroup(Group.GroupGUID);
                                                    //_IGroupRepository.Save();
                                                    _ITerritoryRepository.DeleteTerritoryByRegionGUID(Region.RegionGUID);
                                                    //_ITerritoryRepository.Save();
                                                    _IRegionRepository.DeleteRegion(Region.RegionGUID);
                                                    //_IRegionRepository.Save();


                                                    _IUserSubscriptionRepository.DeleteUserSubscription(userSubscription.UserSubscriptionGUID);
                                                    //_IUserSubscriptionRepository.Save();
                                                    _IUserProfileRepository.DeleteUserProfile(userprofile.ProfileGUID);
                                                    //_IUserProfileRepository.Save();
                                                    _IGlobalUserRepository.DeleteGlobalUser(globalUser.UserGUID);
                                                    //_IGlobalUserRepository.Save();
                                                    _IUserRepository.DeleteUser(aspnetuser.Id);
                                                    // _IUserRepository.Save();
                                                }
                                            }
                                            else
                                            {
                                                //_IGroupRepository.DeleteGroup(Group.GroupGUID);
                                                //_IGroupRepository.Save();
                                                _ITerritoryRepository.DeleteTerritoryByRegionGUID(Region.RegionGUID);
                                                //_ITerritoryRepository.Save();
                                                _IRegionRepository.DeleteRegion(Region.RegionGUID);
                                                // _IRegionRepository.Save();


                                                _IUserSubscriptionRepository.DeleteUserSubscription(userSubscription.UserSubscriptionGUID);
                                                //_IUserSubscriptionRepository.Save();
                                                _IUserProfileRepository.DeleteUserProfile(userprofile.ProfileGUID);
                                                //_IUserProfileRepository.Save();
                                                _IGlobalUserRepository.DeleteGlobalUser(globalUser.UserGUID);
                                                //_IGlobalUserRepository.Save();
                                                _IUserRepository.DeleteUser(aspnetuser.Id);
                                                //_IUserRepository.Save();

                                                _IOrganizationSubscriptionRepository.DeleteOrganizationSubscription(organizationSubscription.OrganizationSubscriptionGUID);
                                                //_IOrganizationSubscriptionRepository.Save();
                                                //_IUserSubscriptionRepository.Save();
                                                _IOrganizationRepository.DeleteOrganization(Organization.OrganizationGUID);
                                                //_IOrganizationRepository.Save();
                                            }
                                        }
                                        else
                                        {
                                            _IOrganizationRepository.DeleteOrganizationUserMap(organizationUserMap.OrganizationUserMapGUID);
                                            //_IOrganizationRepository.Save();
                                            _ITerritoryRepository.DeleteTerritoryByRegionGUID(Region.RegionGUID);
                                            //_ITerritoryRepository.Save();
                                            _IRegionRepository.DeleteRegion(Region.RegionGUID);
                                            //_IRegionRepository.Save();


                                            _IUserSubscriptionRepository.DeleteUserSubscription(userSubscription.UserSubscriptionGUID);
                                            //_IUserSubscriptionRepository.Save();
                                            _IUserProfileRepository.DeleteUserProfile(userprofile.ProfileGUID);
                                            //_IUserProfileRepository.Save();
                                            _IGlobalUserRepository.DeleteGlobalUser(globalUser.UserGUID);
                                            //_IGlobalUserRepository.Save();
                                            _IUserRepository.DeleteUser(aspnetuser.Id);
                                            //_IUserRepository.Save();

                                            _IOrganizationSubscriptionRepository.DeleteOrganizationSubscription(organizationSubscription.OrganizationSubscriptionGUID);
                                            //_IOrganizationSubscriptionRepository.Save();
                                            //_IUserSubscriptionRepository.Save();
                                            _IOrganizationRepository.DeleteOrganization(Organization.OrganizationGUID);
                                            //_IOrganizationRepository.Save();
                                        }
                                    }
                                    else
                                    {
                                        //_IGroupRepository.DeleteGroup(Group.GroupGUID);
                                        //_IGroupRepository.Save();
                                        _ITerritoryRepository.DeleteTerritoryByRegionGUID(Region.RegionGUID);
                                        //_ITerritoryRepository.Save();
                                        _IRegionRepository.DeleteRegion(Region.RegionGUID);
                                        // _IRegionRepository.Save();


                                        _IUserSubscriptionRepository.DeleteUserSubscription(userSubscription.UserSubscriptionGUID);
                                        //_IUserSubscriptionRepository.Save();
                                        _IUserProfileRepository.DeleteUserProfile(userprofile.ProfileGUID);
                                        // _IUserProfileRepository.Save();
                                        _IGlobalUserRepository.DeleteGlobalUser(globalUser.UserGUID);
                                        //_IGlobalUserRepository.Save();
                                        _IUserRepository.DeleteUser(aspnetuser.Id);
                                        //_IUserRepository.Save();

                                        _IOrganizationSubscriptionRepository.DeleteOrganizationSubscription(organizationSubscription.OrganizationSubscriptionGUID);
                                        //_IOrganizationSubscriptionRepository.Save();
                                        //_IUserSubscriptionRepository.Save();
                                        _IOrganizationRepository.DeleteOrganization(Organization.OrganizationGUID);
                                        //_IOrganizationRepository.Save();
                                    }
                                }
                                else
                                {
                                    _IGlobalUserRepository.DeleteGlobalUser(globalUser.UserGUID);
                                    //_IGlobalUserRepository.Save();
                                    _IUserRepository.DeleteUser(aspnetuser.Id);
                                    // _IUserRepository.Save();
                                    _IOrganizationRepository.DeleteOrganization(Organization.OrganizationGUID);
                                    //_IOrganizationRepository.Save();
                                }
                            }
                            else
                            {
                                _IUserRepository.DeleteUser(aspnetuser.Id);
                                // _IUserRepository.Save();
                                _IOrganizationSubscriptionRepository.DeleteOrganizationSubscription(organizationSubscription.OrganizationSubscriptionGUID);
                                //_IOrganizationSubscriptionRepository.Save();
                                _IOrganizationRepository.DeleteOrganization(Organization.OrganizationGUID);
                                // _IOrganizationRepository.Save();
                            }
                        }
                        else
                        {
                            _IOrganizationRepository.DeleteOrganization(Organization.OrganizationGUID);
                            //_IOrganizationRepository.Save();
                        }
                    }
                    else
                    {
                        //UserName already exists
                        TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','Organization Name is Aleady Exists');</script>";
                    }
                }
                return View(organization);

            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return View(organization);
            }
        }
        //
        // GET: /StoreVist/
        public ActionResult Index(string id = "", string customerid = "", string FromDate = "", string ToDate = "", string Date = "", string selection = "", string LastModifiedDate = "", string Visit_RowCount = "", string NonVisit_RowCount = "", int page = 1, string Visit_Search = "", string NonVisit_Search = "", string hdnrecordsize="")
        {
            Logger.Debug("Inside CustomerView Controller- Index");
            try
            {
                ViewBag.CustomerID = customerid;
                ViewBag.FromDate = FromDate;
                ViewBag.ToDate = ToDate;
                ViewBag.Date = Date;
                int visit_TotalPage = 0;
                int visit_TotalRecord = 0;
                int visit_pCount = 0;

                int nonvisit_TotalPage = 0;
                int nonvisit_TotalRecord = 0;
                int nonvisit_pCount = 0;
                if (Session["OrganizationGUID"] != null)
                {
                    if (!string.IsNullOrEmpty(Visit_RowCount))
                    {
                        int.TryParse(Visit_RowCount, out visit_pCount);
                        pageVisitCountList(visit_pCount);
                    }
                    else
                    {
                        pageVisitCountList(visit_pCount);
                    }
                    if (!string.IsNullOrEmpty(NonVisit_RowCount))
                    {
                        int.TryParse(NonVisit_RowCount, out nonvisit_pCount);
                        pageNonVisitCountList(nonvisit_pCount);
                    }
                    else
                    {
                        pageNonVisitCountList(nonvisit_pCount);
                    }

                    if (!string.IsNullOrEmpty(Date))
                    {
                        ViewBag.DateValue = HttpUtility.HtmlDecode(Date);
                        Session["DateValue"] = Date;
                    }
                    else if (!string.IsNullOrEmpty(LastModifiedDate))
                    {
                        Logger.Debug("Inside Last Modfied dislay");
                        if (!string.IsNullOrEmpty(FromDate) && !string.IsNullOrEmpty(ToDate))
                        {
                            DateTime pFrom = new DateTime(), pTo = new DateTime();
                            if (ParseExact(FromDate, "dd-MM-yyyy", out pFrom))
                            {
                                ParseExact(ToDate, "dd-MM-yyyy", out pTo);
                                Logger.Debug("Inside");
                                string datevalue = pFrom.ToString("MMMM d, yyyy") + " - " + pTo.ToString("MMMM d, yyyy");
                                ViewBag.DateValue = datevalue;
                                Session["DateValue"] = datevalue;
                            }
                            else
                            {
                                Logger.Debug("OutSide");
                                string datevalue = DateTime.Now.AddDays(-29).ToString("MMMM d, yyyy") + " - " + DateTime.Now.ToString("MMMM d, yyyy");
                                ViewBag.DateValue = datevalue;
                                Session["DateValue"] = datevalue;
                            }
                            Logger.Debug("From Parst : " + pFrom);
                            Logger.Debug("To Parse : " + pTo);
                        }
                        else
                        {
                            Logger.Debug("OutSide1");
                            string datevalue = DateTime.Now.AddDays(-29).ToString("MMMM d, yyyy") + " - " + DateTime.Now.ToString("MMMM d, yyyy");
                            ViewBag.DateValue = datevalue;
                            Session["DateValue"] = datevalue;
                        }
                    }
                    else
                    {
                        Logger.Error("OutSide2");
                        string datevalue = DateTime.Now.AddDays(-29).ToString("MMMM d, yyyy") + " - " + DateTime.Now.ToString("MMMM d, yyyy");
                        ViewBag.DateValue = datevalue;
                        Session["DateValue"] = datevalue;
                    }
                    StoreVisitReports pStoreVisitReports = new StoreVisitReports();
                    pStoreVisitReports.StoreVisitList = new List<StoreVisit>();
                    pStoreVisitReports.StoreNonVisitList = new List<MarketModel>();

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

                    StringBuilder sb = new StringBuilder();
                    StringBuilder sb1 = new StringBuilder();
                    sb.Append("<div class='actions'>");
                    sb.Append("<div class='btn-group'>");
                    sb1.Append("<div class='actions'>");
                    sb1.Append("<div class='btn-group'>");
                    if (!string.IsNullOrEmpty(customerid))
                    {
                        Place pplace = _IPlaceRepository.GetPlaceByID(new Guid(customerid));
                        if (pplace != null)
                        {
                            Session["ClientCompanyName"] = pplace.PlaceName;
                            sb.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i>" + pplace.PlaceName + " <i class='icon-angle-down'></i></a>");
                            sb1.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i>" + pplace.PlaceName + " <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>");
                            sb1.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 Client <i class='icon-angle-down'></i></a>");
                            sb1.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i>Select Client <i class='icon-angle-down'></i></a>");
                        }
                    }
                    sb.Append("<ul id='ulworkgroup' style='height:100px;overflow-y:scroll' class='dropdown-menu pull-right'>");
                    sb1.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", new { id = "Visits", selection = "All" }) + ">All</a></li>");
                        //sb1.Append("<li><a href=" + Url.Action("Index", new { id = "Non-Visits", selection = "All" }) + ">All</a></li>");
                        sb.Append("<li><a onclick=\"RedirectAction('Visits','');\">All</a></li>");
                        sb1.Append("<li><a onclick=\"RedirectAction('NonVisits','');\">All</a></li>");
                    }

                    List<Place> PlaceList = _IPlaceRepository.GetPlaceByOrganizationGUID(new Guid(Session["OrganizationGUID"].ToString())).ToList();
                    foreach (Place item in PlaceList)
                    {
                        //sb.Append("<li><a href=" + Url.Action("Index", new { id = "Visits", customerid = item.PlaceGUID.ToString() }) + " data-groupguid=" + item.PlaceGUID + ">" + item.PlaceName + "</a></li>");
                        //sb1.Append("<li><a href=" + Url.Action("Index", new { id = "Non-Visits", customerid = item.PlaceGUID.ToString() }) + " data-groupguid=" + item.PlaceGUID + ">" + item.PlaceName + "</a></li>");

                        sb.Append("<li><a onclick=\"RedirectAction('Visits','" + item.PlaceGUID.ToString() + "');\" data-groupguid=" + item.PlaceGUID + ">" + item.PlaceName + "</a></li>");
                        sb1.Append("<li><a onclick=\"RedirectAction('NonVisits','" + item.PlaceGUID.ToString() + "');\" data-groupguid=" + item.PlaceGUID + ">" + item.PlaceName + "</a></li>");
                    }
                    sb.Append("</ul>");
                    sb.Append("</div>");
                    sb.Append("</div>");
                    sb1.Append("</ul>");
                    sb1.Append("</div>");
                    sb1.Append("</div>");
                    ViewBag.CustomerListVisit = sb.ToString();
                    ViewBag.CustomerListNonVisit = sb1.ToString();

                    Market _market = new Market();
                    Job ljob = new Job();
                    ljob.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString());
                    _market.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString());
                    if (!string.IsNullOrEmpty(customerid))
                    {
                        _market.OwnerGUID = new Guid(customerid);
                        ljob.CustomerGUID = new Guid(customerid);
                    }

                    DateTime From, To, Datecontent, LModifiedDate;

                    //LastModifiedDate = _IUserRepository.DecodeFrom64(LastModifiedDate);
                    if (!string.IsNullOrEmpty(LastModifiedDate) && ParseExact(LastModifiedDate, "dd-MM-yyyy", out LModifiedDate))
                    {
                        ljob.LastModifiedDate = LModifiedDate;
                        _market.LastStoreVisitedDate = LModifiedDate;
                    }
                    else if (!string.IsNullOrEmpty(FromDate) && ParseExact(FromDate, "dd-MM-yyyy", out From))
                        _market.LastStoreVisitedDate = From;
                    else
                        _market.LastStoreVisitedDate = DateTime.Now.AddDays(-29);

                    if (!string.IsNullOrEmpty(FromDate) && ParseExact(FromDate, "dd-MM-yyyy", out From))
                    {
                        ljob.ActualStartTime = From;
                    }
                    else
                    {
                        Logger.Error("From Else");
                        ljob.ActualStartTime = DateTime.Now.AddDays(-29);
                    }
                    if (!string.IsNullOrEmpty(ToDate) && ParseExact(ToDate, "dd-MM-yyyy", out To))
                    {
                        ljob.ActualEndTime = To;
                    }
                    else
                    {
                        Logger.Error("To Else");
                        ljob.ActualEndTime = DateTime.Now;
                    }
                    ljob.JobName = "Store Visit";
                    Logger.Debug("Job Object" + Newtonsoft.Json.JsonConvert.SerializeObject(ljob));

                    //FOr Regional Manager
                    if (Session["UserType"] != null && !string.IsNullOrEmpty(Session["UserType"].ToString()) && Session["UserType"].ToString() == "ENT_U_RM" && Session["UserGUID"] != null)
                    {
                        OrganizationUsersMap OrgUserMap = _IOrganizationRepository.GetOrganizationUserMapByUserGUID(new Guid(Session["UserGUID"].ToString()), ljob.OrganizationGUID);
                        if (OrgUserMap != null)
                        {
                            ljob.RegionGUID = OrgUserMap.RegionGUID;
                            _market.RegionGUID = OrgUserMap.RegionGUID;
                        }
                    }

                    //check the current user is Field Manager or not
                    if (Session["UserType"] != null && !string.IsNullOrEmpty(Session["UserType"].ToString()) && Session["UserType"].ToString() == "ENT_U" && Session["UserGUID"] != null)
                    {
                        GlobalUser globalUser = _IGlobalUserRepository.GetGlobalUserByID(new Guid(Session["UserGUID"].ToString()));
                        if (globalUser != null)
                        {
                            ljob.AssignedUserGUID = globalUser.UserGUID;
                            _market.FMUserID = globalUser.USERID;
                        }
                    }

                    List<Job> lstorevisit = _IJobRepository.GetStoreVisitJobs(ljob);
                    List<Market> lstorenonvisit = new List<Market>();
                    lstorenonvisit = _IMarketRepository.GetStoreNonVisit(_market);
                    if (lstorevisit != null && lstorevisit.Count > 0)
                    {
                        ViewBag.Visit_Search = Visit_Search;
                        if (!string.IsNullOrEmpty(Visit_Search))
                        {
                            Visit_Search = Visit_Search.ToLower();
                            lstorevisit = lstorevisit.Where(
                                p => (!String.IsNullOrEmpty(_IRegionRepository.GetRegionNameByRegionGUID(new Guid(p.RegionGUID.ToString()))) && _IRegionRepository.GetRegionNameByRegionGUID(new Guid(p.RegionGUID.ToString())).ToLower().Contains(Visit_Search))
                            || (!String.IsNullOrEmpty(p.CustomerStopGUID.ToString()) && _IMarketRepository.GetMarketByID(new Guid(p.CustomerStopGUID.ToString())).MarketID.ToLower().Contains(Visit_Search))
                            || (!String.IsNullOrEmpty(p.PONumber) && _IMarketRepository.GetMarketByCustomerID(p.OrganizationGUID, _IPORepository.GetPObyPoNumber(p.PONumber).PlaceID, _IPORepository.GetPObyPoNumber(p.PONumber).MarketID).MarketID.ToLower().Contains(Visit_Search))
                            || (!String.IsNullOrEmpty(p.CustomerStopGUID.ToString()) && _IMarketRepository.GetMarketByID(new Guid(p.CustomerStopGUID.ToString())).MarketName.ToLower().Contains(Visit_Search))
                            || (!String.IsNullOrEmpty(p.PONumber) && _IMarketRepository.GetMarketByCustomerID(p.OrganizationGUID, _IPORepository.GetPObyPoNumber(p.PONumber).PlaceID, _IPORepository.GetPObyPoNumber(p.PONumber).MarketID).MarketName.ToLower().Contains(Visit_Search))
                            || (!String.IsNullOrEmpty(_IJobRepository.GetStatusName((int)p.StatusCode)) && _IJobRepository.GetStatusName((int)p.StatusCode).ToLower().Contains(Visit_Search))
                            || (!String.IsNullOrEmpty(_IUserProfileRepository.GetUserProfileByUserID(_IGlobalUserRepository.GetGlobalUserByID(new Guid(p.ManagerUserGUID.ToString())).UserGUID, p.OrganizationGUID).ToString()) && _IUserProfileRepository.GetUserProfileByUserID(_IGlobalUserRepository.GetGlobalUserByID(new Guid(p.ManagerUserGUID.ToString())).UserGUID, p.OrganizationGUID).ToString().ToLower().Contains(Visit_Search))).ToList();
                        }

                        visit_TotalRecord = lstorevisit.ToList().Count;
                        visit_TotalPage = (visit_TotalRecord / (int)ViewBag.pageVisitCountValue) + ((visit_TotalRecord % (int)ViewBag.pageVisitCountValue) > 0 ? 1 : 0);

                        ViewBag.Visit_TotalRows = visit_TotalRecord;
                        lstorevisit = lstorevisit.OrderBy(a => a.OrganizationGUID).Skip(((page - 1) * (int)ViewBag.pageVisitCountValue)).Take((int)ViewBag.pageVisitCountValue).ToList();

                        foreach (Job job in lstorevisit)
                        {
                            StoreVisit storevisit = ConvertToStoreVisit(job);
                            if (storevisit != null)
                            {
                                pStoreVisitReports.StoreVisitList.Add(storevisit);
                            }
                        }
                    }

                    // Logger.Debug("Store Non Visit Count : " + lstorenonvisit.Count);
                    if (lstorenonvisit != null && lstorenonvisit.Count > 0)
                    {
                        ViewBag.NonVisit_Search = NonVisit_Search;
                        if (!string.IsNullOrEmpty(NonVisit_Search))
                        {
                            NonVisit_Search = NonVisit_Search.ToLower();
                            lstorenonvisit = lstorenonvisit.Where(
                                p => (!String.IsNullOrEmpty(p.RegionName) && p.RegionName.ToLower().Contains(NonVisit_Search))
                            || (!String.IsNullOrEmpty(p.MarketID) && p.MarketID.ToLower().Contains(NonVisit_Search))
                            || (!String.IsNullOrEmpty(p.MarketName) && p.MarketName.ToLower().Contains(NonVisit_Search))).ToList();
                        }

                        nonvisit_TotalRecord = lstorenonvisit.ToList().Count;
                        nonvisit_TotalPage = (nonvisit_TotalRecord / (int)ViewBag.pageNonCountValue) + ((nonvisit_TotalRecord % (int)ViewBag.pageNonCountValue) > 0 ? 1 : 0);

                        ViewBag.NonVisit_TotalRows = nonvisit_TotalRecord;
                        lstorenonvisit = lstorenonvisit.OrderBy(a => a.OrganizationGUID).Skip(((page - 1) * (int)ViewBag.pageNonCountValue)).Take((int)ViewBag.pageNonCountValue).ToList();

                        foreach (Market market in lstorenonvisit)
                        {
                            MarketModel _marketModel = ConvertToStoreNonVisit(market);
                            if (_marketModel != null)
                            {
                                pStoreVisitReports.StoreNonVisitList.Add(_marketModel);
                            }
                        }
                    }
                    Session["StoreVisit"] = pStoreVisitReports.StoreVisitList;
                    Session["StoreNonVisit"] = pStoreVisitReports.StoreNonVisitList;

                    if (!string.IsNullOrEmpty(Visit_RowCount))
                        ViewBag.pageVisitCountValue = int.Parse(Visit_RowCount);
                    else
                        ViewBag.pageVisitCountValue = 5;
                    if (!string.IsNullOrEmpty(NonVisit_RowCount))
                        ViewBag.pageNonCountValue = int.Parse(NonVisit_RowCount);
                    else
                        ViewBag.pageNonCountValue = 5;
                    
                    bool visit = false;
                    bool nonvisit = false;
                    if (null != Request && System.Text.RegularExpressions.Regex.IsMatch(Request.Url.ToString().Replace("-", ""), string.Format(@"\b{0}\b", "Visits")))
                        visit = true;
                    if (null != Request && System.Text.RegularExpressions.Regex.IsMatch(Request.Url.ToString().Replace("-", ""), string.Format(@"\b{0}\b", "NonVisits")))
                        nonvisit = true;

                    if (visit)
                        TempData["TabName"] = "Visits";
                    else if(nonvisit)
                        TempData["TabName"] = "Non-Visits";

                    return View(pStoreVisitReports);
                }
                else
                {
                    return RedirectToAction("SessionTimeOut", "User");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return RedirectToAction("Login", "User");
            }
        }
Ejemplo n.º 4
0
        public MobileMarket ConvertMarketforMobile(Market _market)
        {
            if (_market != null)
            {
                MobileMarket _MobileMarket = new MobileMarket();
                // Market _market = context.Markets.Find(MarketGUID);
                _MobileMarket.MarketGUID = _market.MarketGUID;
                _MobileMarket.RecordStatus = _market.RecordStatus;
                _MobileMarket.IsDefault = _market.IsDefault;
                _MobileMarket.Version = _market.Version;
                _MobileMarket.UserGUID = _market.UserGUID;
                _MobileMarket.EntityType = _market.EntityType;
                _MobileMarket.OrganizationGUID = _market.OrganizationGUID;
                _MobileMarket.OwnerGUID = _market.OwnerGUID;
                _MobileMarket.MarketName = _market.MarketName;
                _MobileMarket.RegionGUID = _market.RegionGUID;
                _MobileMarket.TerritoryGUID = _market.TerritoryGUID;
                _MobileMarket.PrimaryContactGUID = _market.PrimaryContactGUID;
                _MobileMarket.FirstName = _market.FirstName;
                _MobileMarket.LastName = _market.LastName;
                _MobileMarket.MobilePhone = _market.MobilePhone;
                _MobileMarket.MarketPhone = _market.MarketPhone;
                _MobileMarket.HomePhone = _market.HomePhone;
                _MobileMarket.Emails = _market.Emails;
                _MobileMarket.TimeZone = _market.TimeZone;
                _MobileMarket.AddressLine1 = _market.AddressLine1;
                _MobileMarket.AddressLine2 = _market.AddressLine2;
                _MobileMarket.City = _market.City;
                _MobileMarket.State = _market.State;
                _MobileMarket.Country = _market.Country;
                _MobileMarket.ZipCode = _market.ZipCode;
                _MobileMarket.Latitude = _market.Latitude;
                _MobileMarket.Longitude = _market.Longitude;
                _MobileMarket.ImageURL = _market.ImageURL;
                _MobileMarket.CreateDate = convertdate(Convert.ToDateTime(_market.CreateDate));// _market.CreateDate;
                _MobileMarket.UpdatedDate = convertdate(Convert.ToDateTime(_market.UpdatedDate));// _market.UpdatedDate;
                _MobileMarket.IsDeleted = _market.IsDeleted;

                return _MobileMarket;
            }
            else
            {
                return null;
            }
        }
Ejemplo n.º 5
0
        public ActionResult DashBoard(string pDay = "", string selection = "", string pDayUser = "", string selectionUser = "", string RowCount = "", int page = 1, string search = "")
        {
            Logger.Debug("Inside User Controller- Index");
            try
            {
                int totalPage = 0;
                int totalRecord = 0;
                int pCount = 0;

                if (Session["OrganizationGUID"] != null)
                {
                    if (!string.IsNullOrEmpty(RowCount))
                    {
                        int.TryParse(RowCount, out pCount);
                        pageCountList(pCount);

                    }
                    else
                    {
                        pageCountList(pCount);
                    }

                    Job lJob = new Job();
                    lJob.AssignedUserGUID = new Guid(Session["UserGUID"].ToString());
                    lJob.IsDeleted = false;
                    lJob.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString());
                    ViewBag.Flag = "false";

                    #region Dropdown

                    if (Session["UserType"] != null && !string.IsNullOrEmpty(Session["UserType"].ToString()) && Session["UserType"].ToString() == "ENT_A")
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append("<div class='actions'>");
                        sb.Append("<div class='btn-group'>");
                        if (!string.IsNullOrEmpty(pDay))
                        {
                            pDay = _IUserRepository.DecodeFrom64(pDay);
                            sb.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i>" + pDay + " <i class='icon-angle-down'></i></a>");
                        }
                        else
                        {

                            //if (!string.IsNullOrEmpty(selection) && selection == "Current Period")
                            //{
                            sb.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i> Current Period <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 <i class='icon-angle-down'></i></a>");
                            //}

                        }
                        sb.Append("<ul id='ulworkgroup' class='dropdown-menu pull-right'>");


                        //if (!string.IsNullOrEmpty(selection) || selection != "Current Period")
                        //{
                        //    sb.Append("<li><a href=" + Url.Action("DashBoard", "User", new { selection = "Current Period" }) + ">Current Period</a></li>");
                        //}

                        if (!string.IsNullOrEmpty(pDay))
                        {
                            if (pDay != "Current Period")
                            {
                                sb.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDay = _IUserRepository.EncodeTo64("Current Period") }) + " data-groupguid='>Current Period'>Current Period</a></li>");
                            }
                            if (pDay != "Period 2")
                            {
                                sb.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDay = _IUserRepository.EncodeTo64("Period 2") }) + " data-groupguid='Period 2'>Period 2</a></li>");
                            }
                            if (pDay != "Period 3")
                            {
                                sb.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDay = _IUserRepository.EncodeTo64("Period 3") }) + " data-groupguid='Period 3'>Period 3</a></li>");
                            }
                            if (pDay != "Period 4")
                            {
                                sb.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDay = _IUserRepository.EncodeTo64("Period 4") }) + " data-groupguid='Period 4'>Period 4</a></li>");
                            }
                            if (pDay != "Period 5")
                            {
                                sb.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDay = _IUserRepository.EncodeTo64("Period 5") }) + " data-groupguid='Period 5'>Period 5</a></li>");
                            }
                            if (pDay != "Period 6")
                            {
                                sb.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDay = _IUserRepository.EncodeTo64("Period 6") }) + " data-groupguid='Period 6'>Period 6</a></li>");
                            }
                        }
                        else
                        {
                            //sb.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDay = _IUserRepository.EncodeTo64("Current Period") }) + " data-groupguid='Current Period'>Current Period</a></li>");
                            sb.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDay = _IUserRepository.EncodeTo64("Period 2") }) + " data-groupguid='Period 2'>Period 2</a></li>");
                            sb.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDay = _IUserRepository.EncodeTo64("Period 3") }) + " data-groupguid='Period 3'>Period 3</a></li>");
                            sb.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDay = _IUserRepository.EncodeTo64("Period 4") }) + " data-groupguid='Period 4'>Period 4</a></li>");
                            sb.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDay = _IUserRepository.EncodeTo64("Period 5") }) + " data-groupguid='Period 5'>Period 5</a></li>");
                            sb.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDay = _IUserRepository.EncodeTo64("Period 6") }) + " data-groupguid='Period 6'>Period 6</a></li>");

                        }
                        sb.Append("</ul>");
                        sb.Append("</div>");
                        sb.Append("</div>");

                        ViewBag.FilterList = sb.ToString();
                    }
                    else
                    {
                        ViewBag.FilterList = "";
                    }
                    #endregion

                    #region Dropdown User Activity
                    StringBuilder sbUser = new StringBuilder();
                    sbUser.Append("<div class='actions'>");
                    sbUser.Append("<div class='btn-group'>");
                    if (!string.IsNullOrEmpty(pDayUser))
                    {
                        pDayUser = _IUserRepository.DecodeFrom64(pDayUser);
                        sbUser.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i>" + pDayUser + " <i class='icon-angle-down'></i></a>");
                    }
                    else
                    {

                        if (!string.IsNullOrEmpty(selectionUser) && selectionUser == "All")
                        {
                            sbUser.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
                        {
                            sbUser.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i> Select <i class='icon-angle-down'></i></a>");
                        }

                    }
                    sbUser.Append("<ul id='ulworkgroup' class='dropdown-menu pull-right'>");


                    if (string.IsNullOrEmpty(selectionUser) || selectionUser != "All")
                    {
                        sbUser.Append("<li><a href=" + Url.Action("Dashboard", "User", new { selectionUser = "******" }) + ">All</a></li>");
                    }

                    if (!string.IsNullOrEmpty(pDayUser))
                    {
                        if (pDayUser != "Today")
                        {
                            sbUser.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDayUser = _IUserRepository.EncodeTo64("Today") }) + " data-groupguid='Today'>Today</a></li>");
                        }
                        if (pDayUser != "7 Days")
                        {
                            sbUser.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDayUser = _IUserRepository.EncodeTo64("7 Days") }) + " data-groupguid='7 Days'>7 Days</a></li>");
                        }
                        if (pDayUser != "30 Days")
                        {
                            sbUser.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDayUser = _IUserRepository.EncodeTo64("30 Days") }) + " data-groupguid=30 Days'>30 Days</a></li>");
                        }
                    }
                    else
                    {
                        sbUser.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDayUser = _IUserRepository.EncodeTo64("Today") }) + " data-groupguid='Today'>Today</a></li>");
                        sbUser.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDayUser = _IUserRepository.EncodeTo64("7 Days") }) + " data-groupguid='7 Days'>7 Days</a></li>");
                        sbUser.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDayUser = _IUserRepository.EncodeTo64("30 Days") }) + " data-groupguid=30 Days'>30 Days</a></li>");
                    }
                    sbUser.Append("</ul>");
                    sbUser.Append("</div>");
                    sbUser.Append("</div>");

                    ViewBag.UserActivityDropdown = sbUser.ToString();
                    #endregion




                    #region Pie Chart
                    Market _Market = new Market();
                    _Market.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString());
                    if (!string.IsNullOrEmpty(pDay))
                    {
                        switch (pDay)
                        {

                            case "Current Period":
                                _Market.LastStoreVisitedDate = DateTime.UtcNow.Date.AddDays(-45);
                                ViewBag.LastModifiedDate = DateTime.UtcNow.Date.AddDays(-45).ToString("dd-MM-yyyy");
                                ViewBag.FromDate = DateTime.UtcNow.Date.AddDays(-45).ToString("dd-MM-yyyy");
                                ViewBag.ToDate = DateTime.UtcNow.Date.ToString("dd-MM-yyyy");
                                break;

                            case "Period 2":
                                _Market.LastStoreVisitedDate = DateTime.UtcNow.Date.AddDays(-52);
                                ViewBag.LastModifiedDate = DateTime.UtcNow.Date.AddDays(-52).ToString("dd-MM-yyyy");
                                ViewBag.FromDate = DateTime.UtcNow.Date.AddDays(-52).ToString("dd-MM-yyyy");
                                ViewBag.ToDate = DateTime.UtcNow.Date.ToString("dd-MM-yyyy");
                                break;
                            case "Period 3":
                                _Market.LastStoreVisitedDate = DateTime.UtcNow.Date.AddDays(-59);
                                ViewBag.LastModifiedDate = DateTime.UtcNow.Date.AddDays(-59).ToString("dd-MM-yyyy");
                                ViewBag.FromDate = DateTime.UtcNow.Date.AddDays(-59).ToString("dd-MM-yyyy");
                                ViewBag.ToDate = DateTime.UtcNow.Date.ToString("dd-MM-yyyy");
                                break;
                            case "Period 4":
                                _Market.LastStoreVisitedDate = DateTime.UtcNow.Date.AddDays(-66);
                                ViewBag.LastModifiedDate = DateTime.UtcNow.Date.AddDays(-66).ToString("dd-MM-yyyy");
                                ViewBag.FromDate = DateTime.UtcNow.Date.AddDays(-66).ToString("dd-MM-yyyy");
                                ViewBag.ToDate = DateTime.UtcNow.Date.ToString("dd-MM-yyyy");
                                break;
                            case "Period 5":
                                _Market.LastStoreVisitedDate = DateTime.UtcNow.Date.AddDays(-73);
                                ViewBag.LastModifiedDate = DateTime.UtcNow.Date.AddDays(-73).ToString("dd-MM-yyyy");
                                ViewBag.FromDate = DateTime.UtcNow.Date.AddDays(-73).ToString("dd-MM-yyyy");
                                ViewBag.ToDate = DateTime.UtcNow.Date.ToString("dd-MM-yyyy");
                                break;
                            case "Period 6":
                                _Market.LastStoreVisitedDate = DateTime.UtcNow.Date.AddDays(-80);
                                ViewBag.LastModifiedDate = DateTime.UtcNow.Date.AddDays(-80).ToString("dd-MM-yyyy");
                                ViewBag.FromDate = DateTime.UtcNow.Date.AddDays(-80).ToString("dd-MM-yyyy");
                                ViewBag.ToDate = DateTime.UtcNow.Date.ToString("dd-MM-yyyy");
                                break;
                            default:
                                _Market.LastStoreVisitedDate = DateTime.UtcNow.Date.AddDays(-45);
                                ViewBag.LastModifiedDate = DateTime.UtcNow.Date.AddDays(-45).ToString("dd-MM-yyyy");
                                ViewBag.FromDate = DateTime.UtcNow.Date.AddDays(-45).ToString("dd-MM-yyyy");
                                ViewBag.ToDate = DateTime.UtcNow.Date.ToString("dd-MM-yyyy");
                                break;

                        }
                    }
                    else
                    {
                        _Market.LastStoreVisitedDate = DateTime.UtcNow.Date.AddDays(-45);
                        ViewBag.LastModifiedDate = DateTime.UtcNow.Date.AddDays(-45).ToString("dd-MM-yyyy");
                        ViewBag.FromDate = DateTime.UtcNow.Date.AddDays(-45).ToString("dd-MM-yyyy");
                        ViewBag.ToDate = DateTime.UtcNow.Date.ToString("dd-MM-yyyy");
                    }
                    int jobCount = 0;
                    // List<Job> pjobVistList = pjobList.Where(x => x.LastModifiedDate >= DateTime.UtcNow.AddDays(-45)).ToList();
                    string FieldManagerName = string.Empty;
                    List<Market> pAllStoreList = new List<Market>();
                    List<Market> pStoreNonVistList = new List<Market>();


                    //FOr Regional Manager
                    if (Session["UserType"] != null && !string.IsNullOrEmpty(Session["UserType"].ToString()) && Session["UserType"].ToString() == "ENT_U_RM" && Session["UserGUID"] != null)
                    {
                        OrganizationUsersMap OrgUserMap = _IOrganizationRepository.GetOrganizationUserMapByUserGUID(new Guid(Session["UserGUID"].ToString()), new Guid(Session["OrganizationGUID"].ToString()));
                        if (OrgUserMap != null)
                        {
                            _Market.RegionGUID = OrgUserMap.RegionGUID;
                        }
                    }

                    //check the current user is Field Manager or not
                    if (Session["UserType"] != null && !string.IsNullOrEmpty(Session["UserType"].ToString()) && Session["UserType"].ToString() == "ENT_U" && Session["UserGUID"] != null)
                    {
                        GlobalUser globalUser = _IGlobalUserRepository.GetGlobalUserByID(new Guid(Session["UserGUID"].ToString()));
                        if (globalUser != null)
                        {
                            //FieldManagerName = globalUser.USERID;
                            _Market.FMUserID = globalUser.USERID;
                        }
                    }
                    pStoreNonVistList = _IMarketRepository.GetStoreNonVisit(_Market);
                    pAllStoreList = _IMarketRepository.GetAllStores(_Market);

                    JobStatusPercentageList pJobStatusPercentageList = new JobStatusPercentageList();
                    pJobStatusPercentageList.data = new List<JobStatusPercentage>();
                    if (pAllStoreList != null && pAllStoreList.Count > 0 && pStoreNonVistList != null && pStoreNonVistList.Count > 0)
                    {
                        jobCount = pAllStoreList.Count;
                        JobStatusPercentage rJobStatusPercentage = new JobStatusPercentage();
                        rJobStatusPercentage.label = "Visit";
                        rJobStatusPercentage.data = (int)Math.Round((decimal)((pAllStoreList.Count - pStoreNonVistList.Count) * 100) / jobCount);
                        pJobStatusPercentageList.data.Add(rJobStatusPercentage);

                        JobStatusPercentage pJobStatusPercentage = new JobStatusPercentage();
                        pJobStatusPercentage.label = "Non Visit";
                        pJobStatusPercentage.data = (int)Math.Round((decimal)(pStoreNonVistList.Count * 100) / jobCount);
                        //Convert.ToInt32((pStoreNonVistList.Count * 100) / jobCount);
                        pJobStatusPercentageList.data.Add(pJobStatusPercentage);
                    }

                    if (pJobStatusPercentageList != null && pJobStatusPercentageList.data != null && pJobStatusPercentageList.data.Count > 0)
                    {
                        ViewBag.VisitPercentage = (new System.Web.Script.Serialization.JavaScriptSerializer()).Serialize(pJobStatusPercentageList.data);
                        ViewBag.Series = pJobStatusPercentageList.data.Count;
                        ViewBag.Flag = "true";
                    }
                    #endregion
                    //display UserActivity Graph
                    #region UserActivity Graph
                    Job uJob = new Job();
                    uJob.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString());
                    if (Session["UserType"] != null && !string.IsNullOrEmpty(Session["UserType"].ToString()) && Session["UserType"].ToString() == "ENT_U" && Session["UserGUID"] != null)
                    {
                        GlobalUser globalUser = _IGlobalUserRepository.GetGlobalUserByID(new Guid(Session["UserGUID"].ToString()));
                        if (globalUser != null)
                        {
                            //User Activity
                            uJob.AssignedUserGUID = globalUser.UserGUID;
                        }
                    }
                    //FOr Regional Manager
                    if (Session["UserType"] != null && !string.IsNullOrEmpty(Session["UserType"].ToString()) && Session["UserType"].ToString() == "ENT_U_RM" && Session["UserGUID"] != null)
                    {
                        OrganizationUsersMap OrgUserMap = _IOrganizationRepository.GetOrganizationUserMapByUserGUID(new Guid(Session["UserGUID"].ToString()), new Guid(Session["OrganizationGUID"].ToString()));
                        if (OrgUserMap != null)
                        {
                            uJob.RegionGUID = OrgUserMap.RegionGUID;
                        }
                    }

                    if (!string.IsNullOrEmpty(pDayUser))
                    {
                        if (pDayUser == "Today")
                        {
                            uJob.ActualStartTime = DateTime.UtcNow;
                            uJob.ActualEndTime = DateTime.UtcNow;
                        }
                        if (pDayUser == "7 Days")
                        {
                            uJob.ActualStartTime = DateTime.UtcNow.AddDays(-6);
                            uJob.ActualEndTime = DateTime.UtcNow;
                        }
                        if (pDayUser == "30 Days")
                        {
                            uJob.ActualStartTime = DateTime.UtcNow.AddDays(-30);
                            uJob.ActualEndTime = DateTime.UtcNow;
                        }
                    }
                    ViewBag.Activity = "false";
                    var userActivityJobList = _IJobRepository.Job_UserActivityGraph(uJob) != null ? _IJobRepository.Job_UserActivityGraph(uJob).ToList() : null;
                    if (userActivityJobList != null && userActivityJobList.Count > 0)
                    {
                        //  int i = 0;
                        int arrayCount = 0;
                        int[,] myAL;
                        DateTime pdate = DateTime.Now;
                        if (pDayUser == "Today")
                        {
                            arrayCount = 3;
                            myAL = new int[3, 2];
                        }
                        else if (pDayUser == "7 Days")
                        {
                            arrayCount = 9;
                            myAL = new int[9, 2];
                            // pdate = DateTime.Now.AddDays(-7);
                            //pdate = userActivityJobList[0].datevalue;
                            pdate = userActivityJobList[0].GetType().GetProperties()[0].GetValue(userActivityJobList[0], null);
                        }
                        else if (pDayUser == "30 Days")
                        {
                            arrayCount = 32;
                            myAL = new int[32, 2];
                            //pdate = DateTime.Now.AddDays(-30);
                            //pdate = userActivityJobList[0].datevalue;
                            pdate = userActivityJobList[0].GetType().GetProperties()[0].GetValue(userActivityJobList[0], null);
                        }
                        else
                        {
                            //arrayCount = (int)(userActivityJobList[userActivityJobList.Count - 1].datevalue - userActivityJobList[0].datevalue).TotalDays;
                            arrayCount = (int)((userActivityJobList[userActivityJobList.Count - 1].GetType().GetProperties()[0].GetValue(userActivityJobList[userActivityJobList.Count - 1], null)) - (userActivityJobList[0].GetType().GetProperties()[0].GetValue(userActivityJobList[0], null))).TotalDays;
                            myAL = new int[arrayCount, 2];
                            //pdate = userActivityJobList[0].datevalue;
                            pdate = userActivityJobList[0].GetType().GetProperties()[0].GetValue(userActivityJobList[0], null);
                        }

                        //foreach (var item in userActivityJobList)
                        for (int i = 0; i < arrayCount; i++)
                        {
                            myAL[i, 0] = i;
                            int binded = 0;
                            for (int j = 0; j < userActivityJobList.Count; j++)
                            {
                                if (pdate.Date == userActivityJobList[j].GetType().GetProperties()[0].GetValue(userActivityJobList[j], null))
                                {
                                    myAL[i, 1] = userActivityJobList[j].GetType().GetProperties()[1].GetValue(userActivityJobList[j], null);
                                    binded = 1;
                                }
                            }
                            if (binded == 0)
                            {
                                myAL[i, 1] = 0;
                            }
                            pdate = pdate.AddDays(1);
                            ViewBag.Activity = "true";
                        }
                        ViewBag.UserActivityList = (new System.Web.Script.Serialization.JavaScriptSerializer()).Serialize(myAL);
                    }

                    #endregion

                    //ScriptManager.RegisterClientScriptBlock(this, this.Page.GetType(), "function", "", true);

                    #region store non visit

                    List<MarketModel> Marketmodel = new List<MarketModel>();
                    if (pStoreNonVistList != null && pStoreNonVistList.Count > 0)
                    {
                        if (!string.IsNullOrEmpty(search))
                        {
                            search = search.ToLower();
                            pStoreNonVistList = pStoreNonVistList.Where(x => (!String.IsNullOrEmpty(x.RegionName) && x.RegionName.ToLower().Contains(search))
                                    || (!String.IsNullOrEmpty(x.MarketID) && x.MarketID.ToLower().Contains(search))
                                    || (!String.IsNullOrEmpty(x.MarketName) && x.MarketName.ToLower().Contains(search))
                                    ).ToList();
                        }

                        totalRecord = pStoreNonVistList.ToList().Count;
                        totalPage = (totalRecord / (int)ViewBag.pageCountValue) + ((totalRecord % (int)ViewBag.pageCountValue) > 0 ? 1 : 0);

                        ViewBag.TotalRows = totalRecord;
                        pStoreNonVistList = pStoreNonVistList.OrderBy(a => a.OrganizationGUID).Skip(((page - 1) * (int)ViewBag.pageCountValue)).Take((int)ViewBag.pageCountValue).ToList();

                        foreach (Market market in pStoreNonVistList)
                        {
                            Marketmodel.Add(ConvertToStoreNonVisit(market));
                        }
                    }
                    
                    return View(Marketmodel);
                    #endregion
                }


                else
                {
                    //  TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','Session Expired');</script>";
                    return RedirectToAction("SessionTimeOut", "User");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return RedirectToAction("Login", "User");

            }
        }
        private int InsertOrUpdateStore(DataRow dr)
        {
            int result = 0;
            try
            {
                Place _place = _IPlaceRepository.GetPlaceByID(dr["parentid"].ToString(), new Guid(Session["OrganizationGUID"].ToString()));
                Territory _territory = _ITerritoryRepository.GetTerritoryByTerritoryID(dr["marketid"].ToString(), new Guid(Session["OrganizationGUID"].ToString()));
                Market _market = _IMarketRepository.GetMarketByCustomerID(new Guid(Session["OrganizationGUID"].ToString()), dr["parentid"].ToString(), dr["storenum"].ToString());
                //Market _market = _IMarketRepository.GetMarketByCustomerID(new Guid(Session["OrganizationGUID"].ToString()), dr["parentid"].ToString(), dr["storenum"].ToString().PadLeft(4, '0'));

                Regex objphonePattern = new Regex(@"(1?)(-| ?)(\()?([0-9]{3})(\)|-| |\)-|\) )?([0-9]{3})(-| )?([0-9]{3,14}|[0-9]{3,14})");
                Regex objEmailPattern = new Regex(@"[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\.)+[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?");

                //if (_place != null && _territory != null && _market == null && objphonePattern.IsMatch(dr["phone"].ToString()) && objEmailPattern.IsMatch(dr["email"].ToString()))
                //var result = input.ToString().PadLeft(length, '0');leading zero
                if (_place != null)
                {
                    Market Market = new Market();

                    Market.MarketID = dr["storenum"].ToString();
                    //Market.MarketID = Market.MarketID.PadLeft(4, '0');
                    Market.IsDefault = true;
                    if (!string.IsNullOrEmpty(Session["UserGUID"].ToString()) && Session["UserGUID"].ToString() != Guid.Empty.ToString())
                    {
                        Market.UserGUID = new Guid(Session["UserGUID"].ToString());
                    }
                    else
                    {
                        Market.UserGUID = null;
                    }
                    Market.EntityType = 1;
                    if (!string.IsNullOrEmpty(Session["OrganizationGUID"].ToString()) && Session["OrganizationGUID"].ToString() != Guid.Empty.ToString())
                    {
                        Market.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString());
                    }
                    else
                    {
                        Market.OrganizationGUID = null;
                    }
                    if (_place.PlaceGUID != Guid.Empty)
                    {
                        Market.OwnerGUID = _place.PlaceGUID;
                    }
                    else
                    {
                        Market.OwnerGUID = null;
                    }
                    Market.MarketName = dr["name"].ToString();

                    List<Person> _people = _IPeopleRepository.GetPeopleByPlaceGUID(_place.PlaceGUID).ToList();
                    if (_people.Count > 0)
                    {
                        _people = _people.OrderByDescending(x => x.CreatedDate).ToList();
                        if (_people[0].PeopleGUID != Guid.Empty)
                        {
                            Market.PrimaryContactGUID = _people[0].PeopleGUID;
                        }
                        else
                        {
                            Market.PrimaryContactGUID = null;
                        }
                    }
                    else
                    {
                        Market.PrimaryContactGUID = null;
                    }
                    if (_territory != null && _territory.RegionGUID != null && _territory.RegionGUID != Guid.Empty)
                    {
                        Market.RegionGUID = _territory.RegionGUID;
                    }
                    else
                    {
                        Market.RegionGUID = null;
                    }
                    if (_territory != null && _territory.TerritoryGUID != Guid.Empty)
                    {
                        Market.TerritoryGUID = _territory.TerritoryGUID;
                    }
                    else
                    {
                        Market.TerritoryGUID = null;
                    }
                    Market.ParentID = dr["parentid"].ToString();
                    Market.TeritoryID = dr["marketid"].ToString();
                    Market.RMUserID = dr["regionalmanager_userid"].ToString();
                    Market.FMUserID = dr["fieldmanager_userid"].ToString();
                    Market.RegionName = dr["region"].ToString();
                    if (!string.IsNullOrEmpty(dr["regionalmanager_name"].ToString()))
                    {
                        string[] names = dr["regionalmanager_name"].ToString().Split(' ');
                        if (names.Length > 1)
                        {
                            Market.FirstName = names[0].ToString();
                            Market.LastName = names[1].ToString();
                        }
                        else
                        {
                            Market.FirstName = "";
                            Market.LastName = "";
                        }
                    }
                    else
                    {
                        Market.FirstName = "";
                        Market.LastName = "";
                    }
                    Market.MobilePhone = "";
                    Market.MarketPhone = dr["phone"].ToString();
                    Market.HomePhone = dr["phone"].ToString();
                    Market.Emails = dr["email"].ToString();
                    Market.AddressLine1 = dr["addr1"].ToString();
                    Market.AddressLine2 = dr["addr2"].ToString();
                    Market.City = dr["city"].ToString();
                    Market.State = dr["state"].ToString();
                    Market.Country = dr["country"].ToString();
                    Market.ZipCode = dr["postalcode"].ToString();
                    Market.IsDeleted = false;

                    Market.UpdatedDate = DateTime.UtcNow;

                    LatLong latLong = new LatLong();
                    latLong = GetLatLngCode(Market.AddressLine1, Market.AddressLine2, Market.City, Market.State, Market.Country, Market.ZipCode);
                    Market.TimeZone = getTimeZone(latLong.Latitude, latLong.Longitude).ToString();
                    Market.Latitude = latLong.Latitude;
                    Market.Longitude = latLong.Longitude;

                    //As per disscussion with kousik
                    var lWebClient = new WebClient();
                    string lTempData = String.Format(ConfigurationManager.AppSettings.Get("ClientStoreURL"), Market.MarketID);
                    lTempData = lWebClient.DownloadString(lTempData);
                    S_POSStoreResponse lObjPOSResp = new JavaScriptSerializer().Deserialize<S_POSStoreResponse>(lTempData);
                    bool UserCreated = false;
                    if (null == lObjPOSResp || !lObjPOSResp.store.apistatus.Equals("OK"))
                    {
                        //If this returns null, return not found error to the mobile
                    }
                    else
                    {
                        Market.StoreJSON = new JavaScriptSerializer().Serialize(lObjPOSResp);
                        Market.StoreJSON = Convert.ToBase64String(Encoding.UTF8.GetBytes(Market.StoreJSON));

                    }

                    if (_market == null)
                    {
                        Market.MarketGUID = Guid.NewGuid();
                        Market.CreateDate = DateTime.UtcNow;
                        result = _IMarketRepository.InsertMarket(Market);
                        // result = _IMarketRepository.Save();
                    }
                    else
                    {
                        Market.MarketGUID = _market.MarketGUID;
                        Market.CreateDate = _market.CreateDate;
                        result = _IMarketRepository.UpdateMarket(Market);
                        // result = _IMarketRepository.Save();
                    }
                    //no need to create user now, when userid is not available in the global user table
                    //if (result > 0)
                    //{
                    //    UserCreated = CreateUserByStoreJson(lObjPOSResp, Market.RegionGUID, Market.TerritoryGUID);
                    //}
                    return result;
                }
                else
                {
                    return result;
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.InnerException.ToString());
                return result;
            }
        }
        public ActionResult Edit(ServicePointModel market)
        {
            Logger.Debug("Inside ServicePoint Controller- Create Http Post");
            try
            {
                if (Session["OrganizationGUID"] != null)
                {
                    DropdownValues();
                    if (ModelState.IsValid)
                    {
                        Market Market = new Market();
                        Market.MarketGUID = new Guid(market.MarketGUID);
                        Market.IsDefault = true;
                        Market.UserGUID = new Guid(market.UserGUID);
                        Market.EntityType = 0;
                        if (!string.IsNullOrEmpty(market.OrganizationGUID) && market.OrganizationGUID != Guid.Empty.ToString())
                        {
                            Market.OrganizationGUID = new Guid(market.OrganizationGUID);
                        }
                        else
                        {
                            Market.OrganizationGUID = null;
                        }
                        if (!string.IsNullOrEmpty(market.UserGUID) && market.UserGUID != Guid.Empty.ToString())
                        {
                            Market.OwnerGUID = new Guid(market.UserGUID);
                        }
                        else
                        {
                            Market.OwnerGUID = null;
                        }

                        Market.MarketName = market.MarketName;
                        if (!string.IsNullOrEmpty(market.UserGUID) && market.UserGUID != Guid.Empty.ToString())
                        {
                            Market.PrimaryContactGUID = new Guid(market.UserGUID);
                        }
                        else
                        {
                            Market.PrimaryContactGUID = null;
                        }

                        if (!string.IsNullOrEmpty(market.RegionGUID) && market.RegionGUID != Guid.Empty.ToString())
                        {
                            Market.RegionGUID = new Guid(market.RegionGUID);
                        }
                        else
                        {
                            Market.RegionGUID = null;
                        }

                        if (!string.IsNullOrEmpty(market.TerritoryGUID) && market.TerritoryGUID != Guid.Empty.ToString())
                        {
                            Market.TerritoryGUID = new Guid(market.TerritoryGUID);
                        }
                        else
                        {
                            Market.TerritoryGUID = null;
                        }

                        Market.FirstName = market.FirstName;
                        Market.LastName = market.LastName;
                        Market.MobilePhone = market.MobilePhone;
                        Market.MarketPhone = market.MarketPhone;
                        Market.HomePhone = market.HomePhone;
                        Market.Emails = market.Emails;
                        Market.AddressLine1 = market.AddressLine1;
                        Market.AddressLine2 = market.AddressLine2;
                        Market.City = market.City;
                        Market.State = market.State;
                        Market.Country = market.Country;
                        Market.ZipCode = market.ZipCode;
                        Market.IsDeleted = false;
                        Market.CreateDate = market.CreateDate;
                        Market.UpdatedDate = DateTime.UtcNow;

                        LatLong latLong = new LatLong();
                        latLong = GetLatLngCode(Market.AddressLine1, Market.AddressLine2, Market.City, Market.State, Market.Country, Market.ZipCode);
                        Market.TimeZone = getTimeZone(latLong.Latitude, latLong.Longitude).ToString();
                        Market.Latitude = latLong.Latitude;
                        Market.Longitude = latLong.Longitude;
                        int marketUpdateResult = _IMarketRepository.UpdateMarket(Market);
                        //int marketUpdateResult = _IMarketRepository.Save();
                        if (marketUpdateResult > 0)
                        {
                            return RedirectToAction("Index");
                        }

                    }
                    return View(market);
                }
                else
                {
                    return RedirectToAction("SessionTimeOut", "User");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return View(market);
            }
        }
        public ActionResult Edit(MarketViewForCreate marketcreate)
        {
            Logger.Debug("Inside Place Controller- Edit Http Post");
            try
            {
                if (Session["OrganizationGUID"] != null)
                {
                    TempData["TabName"] = "Stores";
                    ViewBag.MarketName = !string.IsNullOrEmpty(marketcreate.MarketModel.MarketName) ? marketcreate.MarketModel.MarketName.ToString() : _IMarketRepository.GetMarketByID(new Guid(marketcreate.MarketModel.MarketGUID)).MarketName;
                    DropdownValues();
                    if (ModelState.IsValid)
                    {
                        MarketModel market = new MarketModel();
                        market = marketcreate.MarketModel;
                        Market Market = new Market();
                        Market.MarketGUID = new Guid(market.MarketGUID);
                        Market.MarketID = market.MarketID;
                        Market.IsDefault = true;
                        if (!string.IsNullOrEmpty(market.UserGUID) && market.UserGUID != Guid.Empty.ToString())
                        {
                            Market.UserGUID = new Guid(market.UserGUID);
                        }
                        else
                        {
                            Market.UserGUID = null;
                        }
                        Market.EntityType = market.EntityType;
                        if (!string.IsNullOrEmpty(market.OrganizationGUID) && market.OrganizationGUID != Guid.Empty.ToString())
                        {
                            Market.OrganizationGUID = new Guid(market.OrganizationGUID);
                        }
                        else
                        {
                            Market.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString());
                        }
                        if (!string.IsNullOrEmpty(market.OwnerGUID) && market.OwnerGUID != Guid.Empty.ToString())
                        {
                            Market.OwnerGUID = new Guid(market.OwnerGUID);
                        }
                        else
                        {
                            Market.OwnerGUID = null;
                        }
                        Market.MarketName = market.MarketName;
                        if (!string.IsNullOrEmpty(market.PrimaryContactGUID) && market.PrimaryContactGUID != Guid.Empty.ToString())
                        {
                            Market.PrimaryContactGUID = new Guid(market.PrimaryContactGUID);
                        }
                        else
                        {
                            Market.PrimaryContactGUID = null;
                        }
                        if (!string.IsNullOrEmpty(market.RegionGUID) && market.RegionGUID != Guid.Empty.ToString())
                        {
                            Market.RegionGUID = new Guid(market.RegionGUID);
                            Region _region = _IRegionRepository.GetRegionByID(new Guid(market.RegionGUID));
                            if (_region != null)
                            {
                                Market.RegionName = _region.Name;
                            }
                        }
                        else
                        {
                            Market.RegionGUID = null;
                        }
                        if (!string.IsNullOrEmpty(market.TerritoryGUID) && market.TerritoryGUID != Guid.Empty.ToString())
                        {
                            Market.TerritoryGUID = new Guid(market.TerritoryGUID);
                            Territory _territory = _ITerritoryRepository.GetTerritoryByID(new Guid(market.TerritoryGUID));
                            if (_territory != null)
                            {
                                Market.TeritoryID = _territory.TerritoryID;
                            }
                        }
                        else
                        {
                            Market.TerritoryGUID = null;
                        }
                        if (!string.IsNullOrEmpty(market.RMUserGUID) && market.RMUserGUID != Guid.Empty.ToString())
                        {
                            GlobalUser _globalUser = _IGlobalUserRepository.GetGlobalUserByID(new Guid(market.RMUserGUID));
                            if (_globalUser != null)
                            {
                                Market.RMUserID = _globalUser.USERID;
                            }
                        }
                        if (!string.IsNullOrEmpty(market.FMUserGUID) && market.FMUserGUID != Guid.Empty.ToString())
                        {
                            GlobalUser _globalUser = _IGlobalUserRepository.GetGlobalUserByID(new Guid(market.FMUserGUID));
                            if (_globalUser != null)
                            {
                                Market.FMUserID = _globalUser.USERID;
                            }
                        }


                        Market.FirstName = market.FirstName;
                        Market.LastName = market.LastName;
                        Market.MobilePhone = market.MobilePhone;
                        Market.MarketPhone = market.MarketPhone;
                        Market.HomePhone = market.HomePhone;
                        Market.Emails = market.Emails;
                        Market.AddressLine1 = market.AddressLine1;
                        Market.AddressLine2 = market.AddressLine2;
                        Market.City = market.City;
                        Market.State = market.State;
                        Market.Country = market.Country;
                        Market.ZipCode = market.ZipCode;
                        Market.CreateDate = Convert.ToDateTime(market.CreateDate);
                        Market.UpdatedDate = DateTime.UtcNow;
                        Market.IsDeleted = false;

                        LatLong latLong = new LatLong();
                        latLong = GetLatLngCode(Market.AddressLine1, Market.AddressLine2, Market.City, Market.State, Market.Country, Market.ZipCode);
                        Market.TimeZone = getTimeZone(latLong.Latitude, latLong.Longitude).ToString();
                        Market.Latitude = latLong.Latitude;
                        Market.Longitude = latLong.Longitude;


                        //As per disscussion with kousik
                        var lWebClient = new WebClient();
                        string lTempData = String.Format(ConfigurationManager.AppSettings.Get("ClientStoreURL"), Market.MarketID);
                        lTempData = lWebClient.DownloadString(lTempData);
                        S_POSStoreResponse lObjPOSResp = new JavaScriptSerializer().Deserialize<S_POSStoreResponse>(lTempData);
                        if (null == lObjPOSResp || !lObjPOSResp.store.apistatus.Equals("OK"))
                        {
                            //If this returns null, return not found error to the mobile
                        }
                        else
                        {
                            Market.StoreJSON = new JavaScriptSerializer().Serialize(lObjPOSResp);
                            Market.StoreJSON = Convert.ToBase64String(Encoding.UTF8.GetBytes(Market.StoreJSON));
                        }


                        int marketUpdateResult = _IMarketRepository.UpdateMarket(Market);
                        //int marketUpdateResult = _IMarketRepository.Save();
                        if (marketUpdateResult > 0)
                        {
                            return RedirectToAction("Index", "CustomerView", new { id = "Stores", customerid = Market.OwnerGUID.ToString() });
                        }
                        else
                        {
                            List<AspUser> RMUserList = new List<AspUser>();
                            var appUser = _IUserProfileRepository.GetUserProfilesbyOrganizationGUID(new Guid(Session["OrganizationGUID"].ToString()), "ENT_U_RM").OrderBy(sort => sort.FirstName).ToList();
                            //if (string.IsNullOrEmpty(id))
                            {
                                RMUserList.Add(new AspUser { FirstName = "None", LastName = "", UserGUID = Guid.Empty.ToString(), OrganizationGUID = "" });
                                foreach (var user in appUser.ToList())
                                {
                                    RMUserList.Add(new AspUser { FirstName = user.FirstName, LastName = user.LastName, UserGUID = user.UserGUID.ToString() });
                                }
                            }
                            List<AspUser> FMUserList = new List<AspUser>();
                            var appUserFM = _IUserProfileRepository.GetUserProfilesbyOrganizationGUID(new Guid(Session["OrganizationGUID"].ToString()), "ENT_U").OrderBy(sort => sort.FirstName).ToList();
                            //if (string.IsNullOrEmpty(id))
                            {
                                FMUserList.Add(new AspUser { FirstName = "None", LastName = "", UserGUID = Guid.Empty.ToString(), OrganizationGUID = "" });
                                foreach (var user in appUserFM.ToList())
                                {
                                    FMUserList.Add(new AspUser { FirstName = user.FirstName, LastName = user.LastName, UserGUID = user.UserGUID.ToString() });
                                }
                            }

                            marketcreate.RMUser = RMUserList.AsEnumerable();
                            marketcreate.FMUser = FMUserList.AsEnumerable();

                            return View(marketcreate);
                        }

                    }
                    else
                    {
                        List<AspUser> RMUserList = new List<AspUser>();
                        var appUser = _IUserProfileRepository.GetUserProfilesbyOrganizationGUID(new Guid(Session["OrganizationGUID"].ToString()), "ENT_U_RM").OrderBy(sort => sort.FirstName).ToList();
                        //if (string.IsNullOrEmpty(id))
                        {
                            RMUserList.Add(new AspUser { FirstName = "None", LastName = "", UserGUID = Guid.Empty.ToString(), OrganizationGUID = "" });
                            foreach (var user in appUser.ToList())
                            {
                                RMUserList.Add(new AspUser { FirstName = user.FirstName, LastName = user.LastName, UserGUID = user.UserGUID.ToString() });
                            }
                        }
                        List<AspUser> FMUserList = new List<AspUser>();
                        var appUserFM = _IUserProfileRepository.GetUserProfilesbyOrganizationGUID(new Guid(Session["OrganizationGUID"].ToString()), "ENT_U").OrderBy(sort => sort.FirstName).ToList();
                        //if (string.IsNullOrEmpty(id))
                        {
                            FMUserList.Add(new AspUser { FirstName = "None", LastName = "", UserGUID = Guid.Empty.ToString(), OrganizationGUID = "" });
                            foreach (var user in appUserFM.ToList())
                            {
                                FMUserList.Add(new AspUser { FirstName = user.FirstName, LastName = user.LastName, UserGUID = user.UserGUID.ToString() });
                            }
                        }
                        marketcreate.RMUser = RMUserList.AsEnumerable();
                        marketcreate.FMUser = FMUserList.AsEnumerable();
                        return View(marketcreate);
                    }
                }
                else
                {
                    return RedirectToAction("SessionTimeOut", "User");
                }

            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return RedirectToAction("Login", "User");
            }
        }
        public List<Market> GetAllStores(Market pMarket)
        {
            try
            {
                //using (var dataContext = new WorkersInMotionDB())
                //{
                //    return (from p in dataContext.Markets
                //            where
                //            (pMarket.OrganizationGUID == Guid.Empty || p.OrganizationGUID == pMarket.OrganizationGUID)
                //            && (pMarket.RegionGUID == null || pMarket.RegionGUID == Guid.Empty || p.RegionGUID == pMarket.RegionGUID)
                //            && (pMarket.OwnerGUID == null || pMarket.OwnerGUID == Guid.Empty || p.OwnerGUID == pMarket.OwnerGUID)
                //            && (pMarket.FMUserID == null || pMarket.FMUserID == string.Empty || p.FMUserID == pMarket.FMUserID)
                //            && (p.IsDeleted == null || p.IsDeleted == false)
                //            select p).OrderBy(x => x.MarketName).ToList();


                //}
                SqlParameter[] Param = new SqlParameter[5];
                Param[0] = new SqlParameter("@pOrganizationGUID", SqlDbType.UniqueIdentifier);
                Param[0].Value = (object)pMarket.OrganizationGUID ?? DBNull.Value;
                Param[1] = new SqlParameter("@pRegionGUID", SqlDbType.UniqueIdentifier);
                Param[1].Value = (object)pMarket.RegionGUID ?? DBNull.Value;
                Param[2] = new SqlParameter("@pOwnerGUID", SqlDbType.UniqueIdentifier);
                Param[2].Value = (object)pMarket.OwnerGUID ?? DBNull.Value;
                Param[3] = new SqlParameter("@pFMUserID", SqlDbType.NVarChar, 50);
                Param[3].Value = (object)pMarket.FMUserID ?? DBNull.Value;
                Param[4] = new SqlParameter("@pIsDeleted", SqlDbType.Bit);
                Param[4].Value = (object)pMarket.IsDeleted ?? DBNull.Value;

                return context.Database.SqlQuery<Market>("select * from Markets where"
                                    + " (OrganizationGUID=@pOrganizationGUID OR @pOrganizationGUID is NULL or @pOrganizationGUID=(cast(cast(0 as binary) as uniqueidentifier)))"
                                    + " AND (RegionGUID=@pRegionGUID OR @pRegionGUID is NULL or @pRegionGUID=(cast(cast(0 as binary) as uniqueidentifier)))"
                                    + " AND (OwnerGUID=@pOwnerGUID OR @pOwnerGUID is NULL or @pOwnerGUID=(cast(cast(0 as binary) as uniqueidentifier)))"
                                    + " AND (FMUserID=@pFMUserID OR @pFMUserID is NULL or @pFMUserID='')"
                                    + " AND (IsDeleted=@pIsDeleted OR @pIsDeleted is NULL)"
                                    + " Order by MarketName", Param).ToList();
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }
Ejemplo n.º 10
0
        public List<Market> GetStoreNonVisit(Market pMarket)
        {
            try
            {
                DateTime date = pMarket.LastStoreVisitedDate != null ? Convert.ToDateTime(pMarket.LastStoreVisitedDate).ToUniversalTime() : DateTime.UtcNow.AddDays(-45);
                //using (var dataContext = new WorkersInMotionDB())
                //{
                //    DateTime date = pMarket.LastStoreVisitedDate != null ? Convert.ToDateTime(pMarket.LastStoreVisitedDate).ToUniversalTime() : DateTime.UtcNow.AddDays(-45);
                //    List<Market> MarketList = (from p in dataContext.Markets
                //                               where
                //                               (pMarket.OrganizationGUID == Guid.Empty || p.OrganizationGUID == pMarket.OrganizationGUID)
                //                               && (pMarket.RegionGUID == null || pMarket.RegionGUID == Guid.Empty || p.RegionGUID == pMarket.RegionGUID)
                //                               && (pMarket.OwnerGUID == null || pMarket.OwnerGUID == Guid.Empty || p.OwnerGUID == pMarket.OwnerGUID)
                //                               && (pMarket.FMUserID == null || pMarket.FMUserID == string.Empty || p.FMUserID == pMarket.FMUserID)
                //                               && (p.IsDeleted == null || p.IsDeleted == false)
                //                               select p).OrderBy(x => x.MarketName).ToList();

                //    if (MarketList != null && MarketList.Count > 0)
                //    {
                //        MarketList = MarketList.Where(p => p.LastStoreVisitedDate == null || (p.LastStoreVisitedDate != null && Convert.ToDateTime(p.LastStoreVisitedDate.Value.Date).Date <= date.Date)).ToList();
                //        return MarketList;
                //    }
                //    return null;

                //}
                SqlParameter[] Param = new SqlParameter[5];
                Param[0] = new SqlParameter("@pOrganizationGUID", SqlDbType.UniqueIdentifier);
                Param[0].Value = (object)pMarket.OrganizationGUID ?? DBNull.Value;
                Param[1] = new SqlParameter("@pRegionGUID", SqlDbType.UniqueIdentifier);
                Param[1].Value = (object)pMarket.RegionGUID ?? DBNull.Value;
                Param[2] = new SqlParameter("@pOwnerGUID", SqlDbType.UniqueIdentifier);
                Param[2].Value = (object)pMarket.OwnerGUID ?? DBNull.Value;
                Param[3] = new SqlParameter("@pFMUserID", SqlDbType.NVarChar, 50);
                Param[3].Value = (object)pMarket.FMUserID ?? DBNull.Value;
                Param[4] = new SqlParameter("@pIsDeleted", SqlDbType.Bit);
                Param[4].Value = (object)pMarket.IsDeleted ?? DBNull.Value;

                List<Market> MarketList = context.Database.SqlQuery<Market>("select * from Markets where"
                                    + " (OrganizationGUID=@pOrganizationGUID OR @pOrganizationGUID is NULL or @pOrganizationGUID=(cast(cast(0 as binary) as uniqueidentifier)))"
                                    + " AND (RegionGUID=@pRegionGUID OR @pRegionGUID is NULL or @pRegionGUID=(cast(cast(0 as binary) as uniqueidentifier)))"
                                    + " AND (OwnerGUID=@pOwnerGUID OR @pOwnerGUID is NULL or @pOwnerGUID=(cast(cast(0 as binary) as uniqueidentifier)))"
                                    + " AND (FMUserID=@pFMUserID OR @pFMUserID is NULL or @pFMUserID='')"
                                    + " AND (IsDeleted=@pIsDeleted OR @pIsDeleted is NULL)"
                                    + " Order by MarketName", Param).ToList();

                if (MarketList != null && MarketList.Count > 0)
                {
                    MarketList = MarketList.Where(p => p.LastStoreVisitedDate == null || (p.LastStoreVisitedDate != null && Convert.ToDateTime(p.LastStoreVisitedDate.Value.Date).Date <= date.Date)).ToList();
                    return MarketList;
                }
                return null;
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }
Ejemplo n.º 11
0
        public int UpdateMarket(Market Market)
        {
            // context.Entry(Market).State = EntityState.Modified;

            SqlParameter[] Param = new SqlParameter[39];
            Param[0] = new SqlParameter("@pMarketGUID", SqlDbType.UniqueIdentifier);
            Param[0].Value = Market.MarketGUID;
            Param[1] = new SqlParameter("@pOrganizationGUID", SqlDbType.UniqueIdentifier);
            Param[1].Value = (object)Market.OrganizationGUID ?? DBNull.Value;
            Param[2] = new SqlParameter("@pMarketID", SqlDbType.NVarChar, 50);
            Param[2].Value = (object)Market.MarketID ?? DBNull.Value;
            Param[3] = new SqlParameter("@pRecordStatus", SqlDbType.Int);
            Param[3].Value = (object)Market.RecordStatus ?? DBNull.Value;
            Param[4] = new SqlParameter("@pIsDefault", SqlDbType.Bit);
            Param[4].Value = (object)Market.IsDefault ?? DBNull.Value;
            Param[5] = new SqlParameter("@pVersion", SqlDbType.Bit);
            Param[5].Value = (object)Market.Version ?? DBNull.Value;
            Param[6] = new SqlParameter("@pUserGUID", SqlDbType.UniqueIdentifier);
            Param[6].Value = (object)Market.UserGUID ?? DBNull.Value;
            Param[7] = new SqlParameter("@pEntityType", SqlDbType.Int);
            Param[7].Value = (object)Market.EntityType ?? DBNull.Value;
            Param[8] = new SqlParameter("@pOwnerGUID", SqlDbType.UniqueIdentifier);
            Param[8].Value = (object)Market.OwnerGUID ?? DBNull.Value;
            Param[9] = new SqlParameter("@pMarketName", SqlDbType.NVarChar, 128);
            Param[9].Value = (object)Market.MarketName ?? DBNull.Value;
            Param[10] = new SqlParameter("@pRegionGUID", SqlDbType.UniqueIdentifier);
            Param[10].Value = (object)Market.RegionGUID ?? DBNull.Value;
            Param[11] = new SqlParameter("@pTerritoryGUID", SqlDbType.UniqueIdentifier);
            Param[11].Value = (object)Market.TerritoryGUID ?? DBNull.Value;
            Param[12] = new SqlParameter("@pPrimaryContactGUID", SqlDbType.UniqueIdentifier);
            Param[12].Value = (object)Market.PrimaryContactGUID ?? DBNull.Value;
            Param[13] = new SqlParameter("@pFirstName", SqlDbType.NVarChar, 50);
            Param[13].Value = (object)Market.FirstName ?? DBNull.Value;
            Param[14] = new SqlParameter("@pLastName", SqlDbType.NVarChar, 50);
            Param[14].Value = (object)Market.LastName ?? DBNull.Value;
            Param[15] = new SqlParameter("@pMobilePhone", SqlDbType.NVarChar, 20);
            Param[15].Value = (object)Market.MobilePhone ?? DBNull.Value;
            Param[16] = new SqlParameter("@pMarketPhone", SqlDbType.NVarChar, 20);
            Param[16].Value = (object)Market.MarketPhone ?? DBNull.Value;
            Param[17] = new SqlParameter("@pHomePhone", SqlDbType.NVarChar, 20);
            Param[17].Value = (object)Market.HomePhone ?? DBNull.Value;
            Param[18] = new SqlParameter("@pEmails", SqlDbType.NVarChar, -1);
            Param[18].Value = (object)Market.Emails ?? DBNull.Value;
            Param[19] = new SqlParameter("@pTimeZone", SqlDbType.NVarChar, 50);
            Param[19].Value = (object)Market.TimeZone ?? DBNull.Value;
            Param[20] = new SqlParameter("@pAddressLine1", SqlDbType.NVarChar, 256);
            Param[20].Value = (object)Market.AddressLine1 ?? DBNull.Value;
            Param[21] = new SqlParameter("@pAddressLine2", SqlDbType.NVarChar, 256);
            Param[21].Value = (object)Market.AddressLine2 ?? DBNull.Value;
            Param[22] = new SqlParameter("@pCity", SqlDbType.NVarChar, 128);
            Param[22].Value = (object)Market.City ?? DBNull.Value;
            Param[23] = new SqlParameter("@pState", SqlDbType.NVarChar, 128);
            Param[23].Value = (object)Market.State ?? DBNull.Value;
            Param[24] = new SqlParameter("@pCountry", SqlDbType.NVarChar, 128);
            Param[24].Value = (object)Market.Country ?? DBNull.Value;
            Param[25] = new SqlParameter("@pZipCode", SqlDbType.NVarChar, 20);
            Param[25].Value = (object)Market.ZipCode ?? DBNull.Value;
            Param[26] = new SqlParameter("@pLatitude", SqlDbType.Float);
            Param[26].Value = (object)Market.Latitude ?? DBNull.Value;
            Param[27] = new SqlParameter("@pLongitude", SqlDbType.Float);
            Param[27].Value = (object)Market.Longitude ?? DBNull.Value;
            Param[28] = new SqlParameter("@pImageURL", SqlDbType.NVarChar, -1);
            Param[28].Value = (object)Market.ImageURL ?? DBNull.Value;
            Param[29] = new SqlParameter("@pCreateDate", SqlDbType.DateTime);
            Param[29].Value = (object)Market.CreateDate ?? DBNull.Value;
            Param[30] = new SqlParameter("@pUpdatedDate", SqlDbType.DateTime);
            Param[30].Value = (object)Market.UpdatedDate ?? DBNull.Value;
            Param[31] = new SqlParameter("@pIsDeleted", SqlDbType.Bit);
            Param[31].Value = (object)Market.IsDeleted ?? DBNull.Value;
            Param[32] = new SqlParameter("@pParentID", SqlDbType.NVarChar, 50);
            Param[32].Value = (object)Market.ParentID ?? DBNull.Value;
            Param[33] = new SqlParameter("@pTeritoryID", SqlDbType.NVarChar, 50);
            Param[33].Value = (object)Market.TeritoryID ?? DBNull.Value;
            Param[34] = new SqlParameter("@pRegionName", SqlDbType.NVarChar, 50);
            Param[34].Value = (object)Market.RegionName ?? DBNull.Value;
            Param[35] = new SqlParameter("@pRMUserID", SqlDbType.NVarChar, 50);
            Param[35].Value = (object)Market.RMUserID ?? DBNull.Value;
            Param[36] = new SqlParameter("@pFMUserID", SqlDbType.NVarChar, 50);
            Param[36].Value = (object)Market.FMUserID ?? DBNull.Value;
            Param[37] = new SqlParameter("@pStoreJSON", SqlDbType.NVarChar, -1);
            Param[37].Value = (object)Market.StoreJSON ?? DBNull.Value;
            Param[38] = new SqlParameter("@pLastStoreVisitedDate", SqlDbType.DateTime);
            Param[38].Value = (object)Market.LastStoreVisitedDate ?? DBNull.Value;

            return context.Database.ExecuteSqlCommand("Update Markets set OrganizationGUID=@pOrganizationGUID,"
            + "MarketID=@pMarketID,RecordStatus=@pRecordStatus,IsDefault=@pIsDefault,Version=@pVersion,UserGUID=@pUserGUID,"
            + "EntityType=@pEntityType,OwnerGUID=@pOwnerGUID,MarketName=@pMarketName,RegionGUID=@pRegionGUID,TerritoryGUID=@pTerritoryGUID,"
            + "PrimaryContactGUID=@pPrimaryContactGUID,FirstName=@pFirstName,LastName=@pLastName,MobilePhone=@pMobilePhone,MarketPhone=@pMarketPhone,"
            + "HomePhone=@pHomePhone,Emails=@pEmails,TimeZone=@pTimeZone,"
            + "AddressLine1=@pAddressLine1,AddressLine2=@pAddressLine2,City=@pCity,State=@pState,Country=@pCountry,"
            + "ZipCode=@pZipCode,Latitude=@pLatitude,Longitude=@pLongitude,ImageURL=@pImageURL,CreateDate=@pCreateDate,"
            + "UpdatedDate=@pUpdatedDate,IsDeleted=@pIsDeleted,ParentID=@pParentID,TeritoryID=@pTeritoryID,RegionName=@pRegionName,"
            + "RMUserID=@pRMUserID,FMUserID=@pFMUserID,StoreJSON=@pStoreJSON,LastStoreVisitedDate=@pLastStoreVisitedDate where MarketGUID=@pMarketGUID", Param);

        }
Ejemplo n.º 12
0
 public int CreateMarket(Market NewMarket)
 {
     //context.Markets.Add(NewMarket);
     //return Save();
     return InsertMarket(NewMarket);
 }