Ejemplo n.º 1
0
        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);
            }
        }
        public ActionResult Contact(PeopleViewForCreate peoplecreate)
        {
            Logger.Debug("Inside Place Controller- Create Http Post");
            try
            {
                if (Session["OrganizationGUID"] != null)
                {
                    if (ModelState.IsValid)
                    {
                        PeopleModel people = new PeopleModel();
                        people = peoplecreate.PeopleModel;
                        Person People = new Person();
                        People.PeopleGUID = Guid.NewGuid();

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


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

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

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

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

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

                        var PeopleViewForCreate = new PeopleViewForCreate();
                        PeopleViewForCreate.PlaceViewModel = placeviewModel;
                        return View(PeopleViewForCreate);
                    }
                }
                else
                {
                    return RedirectToAction("SessionTimeOut", "User");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return View(peoplecreate);
            }
        }
Ejemplo n.º 3
0
        public MobilePeople ConvertPeopleForMobile(Person Person)
        {
            if (Person != null)
            {
                MobilePeople _person = new MobilePeople();
                _person.PeopleGUID = Person.PeopleGUID;
                _person.RecordStatus = Person.RecordStatus;
                _person.UserGUID = Person.UserGUID;
                _person.OrganizationGUID = Person.OrganizationGUID;
                _person.IsPrimaryContact = Person.IsPrimaryContact;
                _person.PlaceGUID = Person.PlaceGUID;
                _person.MarketGUID = Person.MarketGUID;
                _person.FirstName = Person.FirstName;
                _person.LastName = Person.LastName;
                _person.CompanyName = Person.CompanyName;
                _person.MobilePhone = Person.MobilePhone;
                _person.BusinessPhone = Person.BusinessPhone;
                _person.HomePhone = Person.HomePhone;
                _person.Emails = Person.Emails;
                _person.AddressLine1 = Person.AddressLine1;
                _person.AddressLine2 = Person.AddressLine2;
                _person.City = Person.City;
                _person.State = Person.State;
                _person.Country = Person.Country;
                _person.ZipCode = Person.ZipCode;
                _person.CategoryID = Person.CategoryID;
                _person.IsDeleted = Person.IsDeleted;
                _person.ImageURL = Person.ImageURL;
                _person.CreatedDate = convertdate(Convert.ToDateTime(Person.CreatedDate));// Person.CreatedDate;
                _person.UpdatedDate = convertdate(Convert.ToDateTime(Person.UpdatedDate));// Person.UpdatedDate;

                return _person;
            }
            else
            {
                return null;
            }

        }
        public int InsertPeople(Person Person)
        {
            // context.People.Add(Person);
            SqlParameter[] Param = new SqlParameter[25];
            Param[0] = new SqlParameter("@pPeopleGUID", SqlDbType.UniqueIdentifier);
            Param[0].Value = Person.PeopleGUID;
            Param[1] = new SqlParameter("@pRecordStatus", SqlDbType.Int);
            Param[1].Value = (object)Person.RecordStatus ?? DBNull.Value;
            Param[2] = new SqlParameter("@pUserGUID", SqlDbType.UniqueIdentifier);
            Param[2].Value = Person.UserGUID;
            Param[3] = new SqlParameter("@pOrganizationGUID", SqlDbType.UniqueIdentifier);
            Param[3].Value = (object)Person.OrganizationGUID ?? DBNull.Value;
            Param[4] = new SqlParameter("@pIsPrimaryContact", SqlDbType.Bit);
            Param[4].Value = (object)Person.IsPrimaryContact ?? DBNull.Value;
            Param[5] = new SqlParameter("@pPlaceGUID", SqlDbType.UniqueIdentifier);
            Param[5].Value = (object)Person.PlaceGUID ?? DBNull.Value;
            Param[6] = new SqlParameter("@pMarketGUID", SqlDbType.UniqueIdentifier);
            Param[6].Value = (object)Person.MarketGUID ?? DBNull.Value;
            Param[7] = new SqlParameter("@pFirstName", SqlDbType.NVarChar, 50);
            Param[7].Value = (object)Person.FirstName ?? DBNull.Value;
            Param[8] = new SqlParameter("@pLastName", SqlDbType.NVarChar, 50);
            Param[8].Value = (object)Person.LastName ?? DBNull.Value;
            Param[9] = new SqlParameter("@pCompanyName", SqlDbType.NVarChar, 50);
            Param[9].Value = (object)Person.CompanyName ?? DBNull.Value;
            Param[10] = new SqlParameter("@pMobilePhone", SqlDbType.NVarChar, 20);
            Param[10].Value = (object)Person.MobilePhone ?? DBNull.Value;
            Param[11] = new SqlParameter("@pBusinessPhone", SqlDbType.NVarChar, 20);
            Param[11].Value = (object)Person.BusinessPhone ?? DBNull.Value;
            Param[12] = new SqlParameter("@pHomePhone", SqlDbType.NVarChar, 20);
            Param[12].Value = (object)Person.HomePhone ?? DBNull.Value;
            Param[13] = new SqlParameter("@pEmails", SqlDbType.NVarChar, -1);
            Param[13].Value = (object)Person.Emails ?? DBNull.Value;
            Param[14] = new SqlParameter("@pAddressLine1", SqlDbType.NVarChar, 256);
            Param[14].Value = (object)Person.AddressLine1 ?? DBNull.Value;
            Param[15] = new SqlParameter("@pAddressLine2", SqlDbType.NVarChar, 256);
            Param[15].Value = (object)Person.AddressLine2 ?? DBNull.Value;
            Param[16] = new SqlParameter("@pCity", SqlDbType.NVarChar, 128);
            Param[16].Value = (object)Person.City ?? DBNull.Value;
            Param[17] = new SqlParameter("@pState", SqlDbType.NVarChar, 128);
            Param[17].Value = (object)Person.State ?? DBNull.Value;
            Param[18] = new SqlParameter("@pCountry", SqlDbType.NVarChar, 128);
            Param[18].Value = (object)Person.Country ?? DBNull.Value;
            Param[19] = new SqlParameter("@pZipCode", SqlDbType.NVarChar, 20);
            Param[19].Value = (object)Person.ZipCode ?? DBNull.Value;
            Param[20] = new SqlParameter("@pCategoryID", SqlDbType.Int);
            Param[20].Value = (object)Person.CategoryID ?? DBNull.Value;
            Param[21] = new SqlParameter("@pIsDeleted", SqlDbType.Bit);
            Param[21].Value = (object)Person.IsDeleted ?? DBNull.Value;
            Param[22] = new SqlParameter("@pImageURL", SqlDbType.NVarChar, -1);
            Param[22].Value = (object)Person.ImageURL ?? DBNull.Value;
            Param[23] = new SqlParameter("@pCreatedDate", SqlDbType.DateTime);
            Param[23].Value = (object)Person.CreatedDate ?? DBNull.Value;
            Param[24] = new SqlParameter("@pUpdatedDate", SqlDbType.DateTime);
            Param[24].Value = (object)Person.UpdatedDate ?? DBNull.Value;

            return context.Database.ExecuteSqlCommand("insert into People(PeopleGUID,RecordStatus,UserGUID,OrganizationGUID,IsPrimaryContact,PlaceGUID,MarketGUID,FirstName,LastName,CompanyName,"
                    + "MobilePhone,BusinessPhone,HomePhone,Emails,AddressLine1,AddressLine2,City,State,Country,ZipCode,CategoryID,IsDeleted,ImageURL,CreatedDate,UpdatedDate)values"
                    + "(@pPeopleGUID,@pRecordStatus,@pUserGUID,@pOrganizationGUID,@pIsPrimaryContact,@pPlaceGUID,@pMarketGUID,@pFirstName,@pLastName,@pCompanyName,"
                    + "@pMobilePhone,@pBusinessPhone,@pHomePhone,@pEmails,@pAddressLine1,@pAddressLine2,@pCity,@pState,@pCountry,@pZipCode,@pCategoryID,@pIsDeleted,@pImageURL,@pCreatedDate,@pUpdatedDate)", Param);
        }