Exemple #1
0
        public ActionResult Person_Update([DataSourceRequest] DataSourceRequest request, Person _person, string filename, long aid)
        {
            _person.UpdatedBy   = CurrentUser.NameIdentifierInt64;
            _person.UpdatedDate = DateTime.Now;

            bool _valid = false;

            if (_UserBAL.LoginPerson_DuplicationCheckBAL(new Person {
                Email = _person.Email, CreatedBy = _person.CreatedBy
            }) > 0)
            {
                ModelState.AddModelError(lr.UserEmailAlreadyExist, lr.UserEmailAlreadyExist);
                // return Json(lr.UserEmailAlreadyExist, JsonRequestBehavior.AllowGet);
                _valid = false;
            }
            else if (_UserBAL.LoginPerson_DuplicationPhoneNumberUpdateCheckBAL(new Person {
                ContactNumber = _person.ContactNumber, CreatedBy = CurrentUser.CompanyID, ID = _person.ID
            }) > 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
                    {
                        _person.CountryCode = 134;
                        _valid = true;
                        //ModelState.AddModelError(lr.PersonPhoneCountryCode, lr.PersonPhoneNumberProvideCountryocde);
                    }
                    else
                    {
                        _valid = true;
                    }
                }
                else
                {
                    ModelState.AddModelError(lr.PersonContactEmail, lr.PersonEmailorPhoneRequired);
                }
                if (_valid)
                {
                    _person.UpdatedBy = CurrentUser.NameIdentifierInt64;
                    if (_person.CrmClientType == null)
                    {
                        _person.CrmClientType = CRMClientType.Not_Specified;
                    }
                    var result = _PersonBAL.Person_UpdateBAL(_person);
                    _person.ProfilePicture = HandlePersonProfilePicture(filename, _person.ID, aid);
                    if (result != -1)
                    {
                        if (_person.clientstatus == null)
                        {
                            _person.clientstatus = CRMClientType.Not_Specified;
                        }
                        _PersonBAL.ManageAssigned_UpdateBAL(_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.PhoneID > 0)
                        {
                            if (_person.ContactNumber != null)
                            {
                                if (_person.CountryCode == 0)
                                {
                                    _person.CountryCode = 134;
                                }
                                if (_person.CountryCode != 0)//when country code is  provided
                                {
                                    PhoneNumbers _objPhoneNumbers = new PhoneNumbers
                                    {
                                        ID            = _person.PhoneID,
                                        ContactNumber = _person.ContactNumber,
                                        CountryCode   = _person.CountryCode,
                                        IsPrimary     = true,
                                        Extension     = _person.Extension,
                                        UpdatedBy     = CurrentUser.NameIdentifierInt64,
                                        UpdatedDate   = DateTime.Now
                                    };
                                    _objPersonContactBAL.PersonPhoneNumbers_UpdateBAL(_objPhoneNumbers, _person.ID);
                                }
                                else
                                {
                                }
                            }
                        }
                        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
                                {
                                    PhoneNumbers _objPhoneNumbers = new PhoneNumbers
                                    {
                                        ID            = _person.PhoneID,
                                        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.EmailID > 0)
                        {
                            if (_person.Email != null)//when Email is Provided
                            {
                                EmailAddresses _objEmailAddresses = new EmailAddresses
                                {
                                    ID          = _person.EmailID,
                                    Email       = _person.Email,
                                    IsPrimary   = true,
                                    UpdatedBy   = CurrentUser.NameIdentifierInt64,
                                    UpdatedDate = DateTime.Now
                                };
                                _objPersonContactBAL.PersonEmailAddress_UpdateBAL(_objEmailAddresses, _person.ID);
                            }
                        }
                        else
                        {
                            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 };

            if (_person.Flags != null)
            {
                _person.Flags = _person.Flags.Where(i => i != null).ToList();
            }
            //return Json(new object[0].ToDataSourceResult(request, ModelState));
            return(Json(resultData.AsQueryable().ToDataSourceResult(request, ModelState)));
        }