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

                        int placeInsertResult = _IPlaceRepository.UpdatePlace(Place);
                        //int placeInsertResult = _IPlaceRepository.Save();
                        if (placeInsertResult > 0)
                        {
                            return RedirectToAction("Index");
                        }
                        else
                        {
                            return View(place);
                        }
                    }
                    return View(place);
                }
                else
                {
                    return RedirectToAction("SessionTimeOut", "User");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return View(place);
            }
        }
        public ActionResult Create(PlaceModel place)
        {
            Logger.Debug("Inside Place Controller- Create Http Post");
            try
            {
                if (Session["OrganizationGUID"] != null)
                {
                    if (ModelState.IsValid)
                    {
                        Place _place = _IPlaceRepository.GetPlaceByID(place.PlaceID, new Guid(Session["OrganizationGUID"].ToString()));
                        if (_place == null)
                        {
                            Place Place = new Place();
                            Place.PlaceGUID = Guid.NewGuid();
                            Place.UserGUID = new Guid(Session["UserGUID"].ToString());
                            Place.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString());
                            Place.PlaceID = place.PlaceID;
                            Place.PlaceName = place.PlaceName;
                            Place.FirstName = place.FirstName;
                            Place.LastName = place.LastName;
                            Place.MobilePhone = place.MobilePhone;
                            Place.PlacePhone = place.PlacePhone;
                            Place.HomePhone = place.HomePhone;
                            Place.Emails = place.Emails;
                            Place.AddressLine1 = place.AddressLine1;
                            Place.AddressLine2 = place.AddressLine2;
                            Place.City = place.City;
                            Place.State = place.State;
                            Place.Country = place.Country;
                            Place.ZipCode = place.ZipCode;
                            Place.CategoryID = 0;
                            Place.IsDeleted = false;
                            Place.CreateDate = DateTime.UtcNow;
                            Place.UpdatedDate = DateTime.UtcNow;
                            LatLong latLong = new LatLong();
                            latLong = GetLatLngCode(Place.AddressLine1, Place.AddressLine2, Place.City, Place.State, Place.Country, Place.ZipCode);
                            Place.TimeZone = getTimeZone(latLong.Latitude, latLong.Longitude).ToString();

                            Person People = new Person();
                            People.PeopleGUID = Guid.NewGuid();
                            People.UserGUID = Place.UserGUID;
                            People.OrganizationGUID = Place.OrganizationGUID;
                            People.IsPrimaryContact = true;
                            People.PlaceGUID = Place.PlaceGUID;
                            People.FirstName = place.FirstName;
                            People.LastName = place.LastName;
                            People.MobilePhone = place.MobilePhone;
                            People.CompanyName = place.PlaceName;
                            People.BusinessPhone = place.PlacePhone;
                            People.HomePhone = place.HomePhone;
                            People.Emails = place.Emails;
                            People.AddressLine1 = place.AddressLine1;
                            People.AddressLine2 = place.AddressLine2;
                            People.City = place.City;
                            People.State = place.State;
                            People.Country = place.Country;
                            People.ZipCode = place.ZipCode;
                            People.CategoryID = 0;
                            People.IsDeleted = false;
                            People.CreatedDate = DateTime.UtcNow;
                            People.UpdatedDate = DateTime.UtcNow;

                            //Market Market = new Market();
                            //Market.MarketGUID = Guid.NewGuid();
                            //Market.IsDefault = true;
                            //Market.UserGUID = Place.UserGUID;
                            //Market.EntityType = 1;
                            //Market.OrganizationGUID = Place.OrganizationGUID;
                            //Market.OwnerGUID = Place.PlaceGUID;
                            //Market.MarketName = Place.PlaceName;
                            //Market.PrimaryContactGUID = People.PeopleGUID;
                            //Market.FirstName = place.FirstName;
                            //Market.LastName = place.LastName;
                            //Market.MobilePhone = place.MobilePhone;
                            //Market.MarketPhone = place.PlacePhone;
                            //Market.HomePhone = place.HomePhone;
                            //Market.Emails = place.Emails;
                            //Market.AddressLine1 = place.AddressLine1;
                            //Market.AddressLine2 = place.AddressLine2;
                            //Market.City = place.City;
                            //Market.State = place.State;
                            //Market.Country = place.Country;
                            //Market.ZipCode = place.ZipCode;
                            //Market.IsDeleted = false;
                            //Market.CreateDate = DateTime.UtcNow;
                            //Market.UpdatedDate = DateTime.UtcNow;

                            int placeInsertResult = _IPlaceRepository.InsertPlace(Place);
                            //int placeInsertResult = _IPlaceRepository.Save();
                            if (placeInsertResult > 0)
                            {
                                int peopleInsertResult = _IPeopleRepository.InsertPeople(People);
                                // int peopleInsertResult = _IPeopleRepository.Save();
                                if (peopleInsertResult > 0)
                                {
                                    //_IMarketRepository.InsertMarket(Market);
                                    //int marketInsertResult = _IMarketRepository.Save();
                                    //if (marketInsertResult > 0)
                                    //{
                                    return RedirectToAction("Index");
                                    //}
                                    //else
                                    //{
                                    //    _IMarketRepository.DeleteMarket(Market.MarketGUID);
                                    //    _IMarketRepository.Save();
                                    //    _IPeopleRepository.DeletePeople(People.PeopleGUID);
                                    //    _IPeopleRepository.Save();
                                    //    _IPlaceRepository.DeletePlace(Place.PlaceGUID);
                                    //    _IPlaceRepository.Save();
                                    //}
                                }
                                else
                                {
                                    _IPeopleRepository.DeletePeople(People.PeopleGUID);
                                    // _IPeopleRepository.Save();
                                    _IPlaceRepository.DeletePlace(Place.PlaceGUID);
                                    //_IPlaceRepository.Save();
                                }
                            }
                            else
                            {
                                _IPlaceRepository.DeletePlace(Place.PlaceGUID);
                                // _IPlaceRepository.Save();
                            }
                        }
                        else
                        {
                            TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','Client ID already configured');</script>";
                            return View(place);
                        }
                    }
                    else
                    {
                        return View(place);
                    }
                    return View();
                }
                else
                {
                    return RedirectToAction("SessionTimeOut", "User");
                }

            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return View(place);
            }
        }
Esempio n. 3
0
 public MobilePlace ConvertPlaceforMobile(Place Place)
 {
     if (Place != null)
     {
         MobilePlace _place = new MobilePlace();
         _place.PlaceGUID = Place.PlaceGUID;
         _place.PlaceID = Place.PlaceID;
         _place.UserGUID = Place.UserGUID;
         _place.OrganizationGUID = Place.OrganizationGUID;
         _place.PlaceName = Place.PlaceName;
         _place.FirstName = Place.FirstName;
         _place.LastName = Place.LastName;
         _place.MobilePhone = Place.MobilePhone;
         _place.PlacePhone = Place.PlacePhone;
         _place.HomePhone = Place.HomePhone;
         _place.Emails = Place.Emails;
         _place.TimeZone = Place.TimeZone;
         _place.AddressLine1 = Place.AddressLine1;
         _place.AddressLine2 = Place.AddressLine2;
         _place.City = Place.City;
         _place.State = Place.State;
         _place.Country = Place.Country;
         _place.ZipCode = Place.ZipCode;
         _place.CategoryID = Place.CategoryID;
         _place.IsDeleted = Place.IsDeleted;
         _place.ImageURL = Place.ImageURL;
         _place.CreateDate = convertdate(Convert.ToDateTime(Place.CreateDate));// Place.CreateDate;
         _place.UpdatedDate = convertdate(Convert.ToDateTime(Place.UpdatedDate));// Place.UpdatedDate;
         return _place;
     }
     else
     {
         return null;
     }
 }
        public int UpdatePlace(Place place)
        {
            //context.Entry(place).State = EntityState.Modified;
            SqlParameter[] Param = new SqlParameter[23];
            Param[0] = new SqlParameter("@pPlaceGUID", SqlDbType.UniqueIdentifier);
            Param[0].Value = place.PlaceGUID;
            Param[1] = new SqlParameter("@pPlaceID", SqlDbType.NVarChar, 50);
            Param[1].Value = (object)place.PlaceID ?? DBNull.Value;
            Param[2] = new SqlParameter("@pUserGUID", SqlDbType.UniqueIdentifier);
            Param[2].Value = place.UserGUID;
            Param[3] = new SqlParameter("@pOrganizationGUID", SqlDbType.UniqueIdentifier);
            Param[3].Value = (object)place.OrganizationGUID ?? DBNull.Value;
            Param[4] = new SqlParameter("@pPlaceName", SqlDbType.NVarChar, 50);
            Param[4].Value = (object)place.PlaceName ?? DBNull.Value;
            Param[5] = new SqlParameter("@pFirstName", SqlDbType.NVarChar, 50);
            Param[5].Value = (object)place.FirstName ?? DBNull.Value;
            Param[6] = new SqlParameter("@pLastName", SqlDbType.NVarChar, 50);
            Param[6].Value = (object)place.LastName ?? DBNull.Value;
            Param[7] = new SqlParameter("@pMobilePhone", SqlDbType.NVarChar, 20);
            Param[7].Value = (object)place.MobilePhone ?? DBNull.Value;
            Param[8] = new SqlParameter("@pPlacePhone", SqlDbType.NVarChar, 20);
            Param[8].Value = (object)place.PlacePhone ?? DBNull.Value;
            Param[9] = new SqlParameter("@pHomePhone", SqlDbType.NVarChar, 20);
            Param[9].Value = (object)place.HomePhone ?? DBNull.Value;
            Param[10] = new SqlParameter("@pEmails", SqlDbType.NVarChar, -1);
            Param[10].Value = (object)place.Emails ?? DBNull.Value;
            Param[11] = new SqlParameter("@pTimeZone", SqlDbType.NVarChar, 20);
            Param[11].Value = (object)place.TimeZone ?? DBNull.Value;
            Param[12] = new SqlParameter("@pAddressLine1", SqlDbType.NVarChar, 256);
            Param[12].Value = (object)place.AddressLine1 ?? DBNull.Value;
            Param[13] = new SqlParameter("@pAddressLine2", SqlDbType.NVarChar, 256);
            Param[13].Value = (object)place.AddressLine2 ?? DBNull.Value;
            Param[14] = new SqlParameter("@pCity", SqlDbType.NVarChar, 128);
            Param[14].Value = (object)place.City ?? DBNull.Value;
            Param[15] = new SqlParameter("@pState", SqlDbType.NVarChar, 128);
            Param[15].Value = (object)place.State ?? DBNull.Value;
            Param[16] = new SqlParameter("@pCountry", SqlDbType.NVarChar, 128);
            Param[16].Value = (object)place.Country ?? DBNull.Value;
            Param[17] = new SqlParameter("@pZipCode", SqlDbType.NVarChar, 20);
            Param[17].Value = (object)place.ZipCode ?? DBNull.Value;
            Param[18] = new SqlParameter("@pCategoryID", SqlDbType.Int);
            Param[18].Value = (object)place.CategoryID ?? DBNull.Value;
            Param[19] = new SqlParameter("@pIsDeleted", SqlDbType.Bit);
            Param[19].Value = (object)place.IsDeleted ?? DBNull.Value;
            Param[20] = new SqlParameter("@pImageURL", SqlDbType.NVarChar, -1);
            Param[20].Value = (object)place.ImageURL ?? DBNull.Value;
            Param[21] = new SqlParameter("@pCreateDate", SqlDbType.DateTime);
            Param[21].Value = (object)place.CreateDate ?? DBNull.Value;
            Param[22] = new SqlParameter("@pUpdatedDate", SqlDbType.DateTime);
            Param[22].Value = (object)place.UpdatedDate ?? DBNull.Value;

            return context.Database.ExecuteSqlCommand("update Places set PlaceID=@pPlaceID,UserGUID=@pUserGUID,OrganizationGUID=@pOrganizationGUID,"
                     + "PlaceName=@pPlaceName,FirstName=@pFirstName,LastName=@pLastName,MobilePhone=@pMobilePhone,"
                     + "PlacePhone=@pPlacePhone,HomePhone=@pHomePhone,Emails=@pEmails,TimeZone=@pTimeZone,"
                     + "AddressLine1=@pAddressLine1,AddressLine2=@pAddressLine2,City=@pCity,State=@pState,Country=@pCountry,ZipCode=@pZipCode,"
                     + "CategoryID=@pCategoryID,IsDeleted=@pIsDeleted,ImageURL=@pImageURL,CreateDate=@pCreateDate,UpdatedDate=@pUpdatedDate where PlaceGUID=@pPlaceGUID", Param);
        }
        public ActionResult EditCustomer(customerview pcustomerview)
        {
            Logger.Debug("Inside Place Controller- Edit Http Post");
            try
            {
                if (Session["OrganizationGUID"] != null)
                {
                    if (ModelState.IsValid)
                    {
                        if (pcustomerview.PlaceModel != null)
                        {
                            Place Place = new Place();
                            Place.PlaceGUID = new Guid(pcustomerview.PlaceModel.PlaceGUID);
                            Place.UserGUID = new Guid(pcustomerview.PlaceModel.UserGUID);
                            Place.PlaceID = pcustomerview.PlaceModel.PlaceID;
                            Place.OrganizationGUID = !string.IsNullOrEmpty(pcustomerview.PlaceModel.OrganizationGUID) ? new Guid(pcustomerview.PlaceModel.OrganizationGUID) : Guid.Empty;
                            Place.PlaceName = pcustomerview.PlaceModel.PlaceName;
                            Place.FirstName = pcustomerview.PlaceModel.FirstName;
                            Place.LastName = pcustomerview.PlaceModel.LastName;
                            Place.MobilePhone = pcustomerview.PlaceModel.MobilePhone;
                            Place.PlacePhone = pcustomerview.PlaceModel.PlacePhone;
                            Place.HomePhone = pcustomerview.PlaceModel.HomePhone;
                            Place.Emails = pcustomerview.PlaceModel.Emails;
                            Place.AddressLine1 = pcustomerview.PlaceModel.AddressLine1;
                            Place.AddressLine2 = pcustomerview.PlaceModel.AddressLine2;
                            Place.City = pcustomerview.PlaceModel.City;
                            Place.State = pcustomerview.PlaceModel.State;
                            Place.Country = pcustomerview.PlaceModel.Country;
                            Place.ZipCode = pcustomerview.PlaceModel.ZipCode;
                            Place.UpdatedDate = DateTime.UtcNow;
                            LatLong latLong = new LatLong();
                            latLong = GetLatLngCode(Place.AddressLine1, Place.AddressLine2, Place.City, Place.State, Place.Country, Place.ZipCode);
                            Place.TimeZone = getTimeZone(latLong.Latitude, latLong.Longitude).ToString();

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

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