예제 #1
0
        public ActionResult Person_Create([DataSourceRequest] DataSourceRequest request, Person _person)
        {
            if (ModelState.IsValid)
            {
                bool _valid = false;
                if (_UserBAL.LoginPerson_DuplicationCheckBAL(new Person {
                    Email = _person.Email, CreatedBy = CurrentUser.CompanyID
                }) > 0)
                {
                    ModelState.AddModelError(lr.UserEmailAlreadyExist, lr.UserEmailAlreadyExist);
                    // return Json(lr.UserEmailAlreadyExist, JsonRequestBehavior.AllowGet);
                    _valid = false;
                }
                else if (_UserBAL.LoginPerson_DuplicationPhoneNumberCheckBAL(new Person {
                    ContactNumber = _person.ContactNumber, CreatedBy = CurrentUser.CompanyID
                }) > 0)
                {
                    ModelState.AddModelError(lr.DubliocationHappen, lr.PersonContactPhoneDuplicationCheck);
                    //return Json(lr.UserEmailAlreadyExist, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    //if (_person.Email != null)//when Email is Provided
                    //{
                    //    _valid = true;
                    //}
                    //else
                    //if (_person.ContactNumber != null)//when Contact number is provided
                    //{
                    //    if (_person.CountryCode == 0)//when country code is  provided
                    //    {
                    //        ModelState.AddModelError(lr.PersonPhoneCountryCode, lr.PersonPhoneNumberProvideCountryocde);
                    //    }
                    //    else
                    //    {
                    //        _valid = true;
                    //    }
                    //}
                    //else
                    //{
                    //    ModelState.AddModelError(lr.PersonContactEmail, lr.PersonEmailorPhoneRequired);
                    //}
                    _valid = true;
                    if (_valid)
                    {
                        _person.CreatedBy      = CurrentUser.NameIdentifierInt64;
                        _person.CreatedDate    = DateTime.Now;
                        _person.OrganizationID = CurrentUser.CompanyID;
                        string _profilePict = string.Empty;
                        _person.DateOfBirth = DateTime.Now;
                        var Resp = SavePersonData(_person, ref _profilePict);
                        _person.AddedByAlias = CurrentUser.Name;
                        _person.ID           = Resp.ID;
                        long val = Convert.ToInt64(_person.AssignedToString);
                        if (val == 0 || val < 0)
                        {
                            _person.AssignedTo = CurrentUser.NameIdentifierInt64;
                        }
                        else
                        {
                            _person.AssignedTo = val;
                        }
                        _person.PersonRegCode  = Resp.PersonRegCode;
                        _person.ProfilePicture = _profilePict;
                        long crmval = (long)_person.CrmClientType;


                        if (_person.ID != long.MinValue)
                        {
                            _PersonBAL.ManageAssigned_CreateBAL(_person);
                            Library.TMS.Notifications nof = new Library.TMS.Notifications();
                            nof.NotificationText = "Your have assigned a prospect";
                            nof.Organization_ID  = CurrentUser.CompanyID;
                            nof.ToUser           = Convert.ToInt64(_person.AssignedTo);
                            nof.FromUser         = CurrentUser.NameIdentifierInt64;
                            nof.ActionUrl        = "Prospect/Detail?pid=" + _person.ID;
                            nof.Event_ID         = 2;
                            nof.CreatedDate      = DateTime.Now;
                            BALNotification.create_NotificationsBAL(nof);
                            var notificationHub = GlobalHost.ConnectionManager.GetHubContext <NotificationHub>();
                            notificationHub.Clients.All.notify("added");
                            if (_person.ContactNumber != null)//when ContactNumber is Provided
                            {
                                PhoneNumbers _objPhoneNumbers = new PhoneNumbers
                                {
                                    ContactNumber = _person.ContactNumber,
                                    CountryCode   = _person.CountryCode,
                                    IsPrimary     = true,
                                    Extension     = _person.Extension,
                                    CreatedBy     = CurrentUser.NameIdentifierInt64,
                                    CreatedDate   = DateTime.Now
                                };
                                _person.PhoneID = _objPersonContactBAL.PersonPhoneNumbers_CreateBAL(_objPhoneNumbers, _person.ID);
                            }
                            if (_person.Email != null)//when Email is Provided
                            {
                                EmailAddresses _objEmailAddresses = new EmailAddresses
                                {
                                    Email       = _person.Email,
                                    IsPrimary   = true,
                                    CreatedBy   = CurrentUser.NameIdentifierInt64,
                                    CreatedDate = DateTime.Now
                                };
                                _person.EmailID = _objPersonContactBAL.PersonEmailAddress_CreateBAL(_objEmailAddresses, _person.ID);
                            }
                        }
                    }
                }
            }

            var resultData = new[] { _person };

            return(Json(resultData.ToDataSourceResult(request, ModelState)));
        }
예제 #2
0
        public ActionResult Person_Create([DataSourceRequest] DataSourceRequest request, Person _person)
        {
            if (ModelState.IsValid)
            {
                bool _valid = false;
                if (_person.Email != null)//when Email is Provided
                {
                    _valid = true;
                }
                else if (_person.ContactNumber != null) //when Contact number is provided
                {
                    if (_person.CountryCode == 0)       //when country code is  provided
                    {
                        ModelState.AddModelError(lr.PersonPhoneCountryCode, lr.PersonPhoneNumberProvideCountryocde);
                    }
                    else
                    {
                        _valid = true;
                    }
                }
                else
                {
                    ModelState.AddModelError(lr.PersonContactEmail, lr.PersonEmailorPhoneRequired);
                }
                if (_valid)
                {
                    _person.CreatedBy      = CurrentUser.NameIdentifierInt64;
                    _person.CreatedDate    = DateTime.Now;
                    _person.OrganizationID = CurrentUser.CompanyID;
                    string _profilePict = string.Empty;
                    var    Resp         = SavePersonData(_person, ref _profilePict);
                    _person.AddedByAlias = CurrentUser.Name;
                    _person.ID           = Resp.ID;

                    _person.PersonRegCode  = Resp.PersonRegCode;
                    _person.ProfilePicture = _profilePict;
                    if (_person.ID != long.MinValue)
                    {
                        _PersonBAL.ManageAssigned_CreateBAL(_person);

                        if (_person.ContactNumber != null)//when ContactNumber is Provided
                        {
                            PhoneNumbers _objPhoneNumbers = new PhoneNumbers
                            {
                                ContactNumber = _person.ContactNumber,
                                CountryCode   = _person.CountryCode,
                                IsPrimary     = true,
                                Extension     = _person.Extension,
                                CreatedBy     = CurrentUser.NameIdentifierInt64,
                                CreatedDate   = DateTime.Now
                            };
                            _person.PhoneID = _objPersonContactBAL.PersonPhoneNumbers_CreateBAL(_objPhoneNumbers, _person.ID);
                        }
                        if (_person.Email != null)//when Email is Provided
                        {
                            EmailAddresses _objEmailAddresses = new EmailAddresses
                            {
                                Email       = _person.Email,
                                IsPrimary   = true,
                                CreatedBy   = CurrentUser.NameIdentifierInt64,
                                CreatedDate = DateTime.Now
                            };
                            _person.EmailID = _objPersonContactBAL.PersonEmailAddress_CreateBAL(_objEmailAddresses, _person.ID);
                        }
                    }
                }
            }

            var resultData = new[] { _person };

            return(Json(resultData.ToDataSourceResult(request, ModelState)));
        }