Beispiel #1
0
        public CRMContact GetContact(string email)
        {
            if (CRMConnection != null)
            {
                connectCRM();
            }

            string fetchXML =
                @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' returntotalrecordcount='true' >
                            <entity name='contact'>
                                <attribute name='contactid' />
                                <attribute name='fullname' />
                                <attribute name='emailaddress1' />
                                <filter type = 'and'>
                                    <condition attribute = 'emailaddress1' value = " + email + @" operator = 'eq' />
                                </filter>
                            </entity>
                        </fetch>";

            EntityCollection collection = Dynamics365Helper.RetrieveXML(fetchXML);

            CRMContact contact = null;

            if (collection.Entities != null)
            {
                var entity = collection.Entities.FirstOrDefault();
                contact           = new CRMContact();
                contact.Email     = entity.Attributes["emailaddress1"].ToString();
                contact.FullName  = entity.Attributes["fullname"].ToString();
                contact.ContactId = new Guid(entity.Attributes["contactid"].ToString());
            }

            return(contact);
        }
Beispiel #2
0
        //��������ϢҪ������ʷ��¼
        public CRMContact Save(CRMContact entity)
        {
            if (this.dataCtx.Connection != null)
                if (this.dataCtx.Connection.State == ConnectionState.Closed)
                    this.dataCtx.Connection.Open();
            DbTransaction tran = this.dataCtx.Connection.BeginTransaction();
            dataCtx.Transaction = tran;

            try
            {
                var qry = from t in CRMContacts
                          where t.ContactID == entity.ContactID
                          select t;
                var obj = qry.SingleOrDefault();
                if (obj != null)
                {
                    //this.CopyEntity(obj, entity);
                    obj.IsActive = false;   //��ԭ������������Ϣ��IsActive=false
                }
                this.CRMContacts.InsertOnSubmit(entity);

                this.dataCtx.SubmitChanges();
                tran.Commit();
                return entity;
            }
            catch (Exception ex)
            {
                tran.Rollback();
                throw ex;
            }
            finally
            {
                dataCtx.Connection.Close();
            }
        }
        public CRMContact Post(CRMContact contact)
        {
            contact.Id = CRMContacts.Max(t => t.Id) + 1;
            CRMContacts.Add(contact);

            return(contact);
        }
Beispiel #4
0
        private CRMContact GetSaveEntity()
        {
            var entity = new CRMContact();

            if (string.IsNullOrEmpty(txtContactID.Text.Trim()) == false)
            {
                entity.ContactID = int.Parse(txtContactID.Text.Trim());
            }
            if (string.IsNullOrEmpty(txtContactName.Text.Trim()) == false)
            {
                entity.ContactName = txtContactName.Text.Trim();
            }
            if (string.IsNullOrEmpty(txtContactSex.Text.Trim()) == false)
            {
                entity.ContactSex = Boolean.Parse(txtContactSex.Text.Trim());
            }
            if (string.IsNullOrEmpty(txtContactTypeID.Text.Trim()) == false)
            {
                entity.ContactTypeID = int.Parse(txtContactTypeID.Text.Trim());
            }
            if (string.IsNullOrEmpty(txtContactDept.Text.Trim()) == false)
            {
                entity.ContactDept = txtContactDept.Text.Trim();
            }
            if (string.IsNullOrEmpty(txtContactTitle.Text.Trim()) == false)
            {
                entity.ContactTitle = txtContactTitle.Text.Trim();
            }
            if (string.IsNullOrEmpty(txtContactTel.Text.Trim()) == false)
            {
                entity.ContactTel = txtContactTel.Text.Trim();
            }
            if (string.IsNullOrEmpty(txtContactMobile.Text.Trim()) == false)
            {
                entity.ContactMobile = txtContactMobile.Text.Trim();
            }
            if (string.IsNullOrEmpty(txtContactEmail.Text.Trim()) == false)
            {
                entity.ContactEmail = txtContactEmail.Text.Trim();
            }
            if (string.IsNullOrEmpty(txtContactMSN.Text.Trim()) == false)
            {
                entity.ContactMSN = txtContactMSN.Text.Trim();
            }
            if (string.IsNullOrEmpty(txtContactQQ.Text.Trim()) == false)
            {
                entity.ContactQQ = txtContactQQ.Text.Trim();
            }
            if (string.IsNullOrEmpty(txtContactFax.Text.Trim()) == false)
            {
                entity.ContactFax = txtContactFax.Text.Trim();
            }
            if (string.IsNullOrEmpty(txtContactCustID.Text.Trim()) == false)
            {
                entity.ContactCustID = int.Parse(txtContactCustID.Text.Trim());
            }

            entity.IsActive = true;
            return(entity);
        }
        public static List <CRMContact> GetFuneralHomeContacts(CRMFuneralHome crmFuneralHome)
        {
            if (crmFuneralHome.WebsiteProvider == Models.Data.Enums.WebsiteProvider.FuneralNet)
            {
                List <CRMContact> contacts  = new List <CRMContact>();
                string            aboutPage = crmFuneralHome.Website + "/_mgxroot/page_10721.php";
                var pedersenPage            = new HtmlWeb();
                var document         = pedersenPage.Load(aboutPage);
                var funeralHomeNodes = document.DocumentNode.Descendants("h3");
                if (funeralHomeNodes != null)
                {
                    foreach (var node in funeralHomeNodes)
                    {
                        try
                        {
                            CRMContact contact = new CRMContact();
                            contact.CRMFuneralHomeId = crmFuneralHome.Id;
                            contact.CRMFuneralHome   = crmFuneralHome;
                            string fullName = node.InnerText;
                            fullName = fullName.Replace("&nbsp;", "");
                            string firstName = fullName.Substring(0, fullName.IndexOf(' '));
                            string lastName  = fullName.Substring(fullName.IndexOf(' '));
                            firstName         = firstName.Trim();
                            lastName          = lastName.Trim();
                            contact.FirstName = firstName;
                            contact.LastName  = lastName;

                            if (node.NextSibling.NextSibling.Name == "p" || node.NextSibling.NextSibling.Name == "h4")
                            {
                                string websitePosition = node.NextSibling.NextSibling.InnerText;
                                contact.ContactPosition = Models.Data.Enums.ContactPosition.FuneralAttendant;
                                if (websitePosition.Contains("Director") || websitePosition.Contains("Directors"))
                                {
                                    contact.ContactPosition = Models.Data.Enums.ContactPosition.FuneralDirector;
                                }
                                if (websitePosition.Contains("Office"))
                                {
                                    contact.ContactPosition = Models.Data.Enums.ContactPosition.Admin;
                                }
                                if (websitePosition.Contains("Intern"))
                                {
                                    contact.ContactPosition = Models.Data.Enums.ContactPosition.Intern;
                                }
                            }
                            contact.ScreenScrappedImage = GetProfileImage(contact);
                            contact.ScreenScrappedBio   = GetDescription(contact);
                            contacts.Add(contact);
                        }
                        catch
                        {
                        }
                    }

                    return(contacts);
                }
            }

            return(null);
        }
        private void Execute(CRMContact account)
        {
            try
            {
                //ServerConnection serverConnect = new ServerConnection();
                //ServerConnection.Configuration config = serverConnect.GetServerConfiguration();

                QueryandAdd(account.Nickname, account.CustomerOpenID, account.PaOpenID, account.Barcode);
            }
            catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> ex)
            {
                Debug.WriteLine("The application terminated with an error.");
                Debug.WriteLine("Timestamp: {0}", ex.Detail.Timestamp);
                Debug.WriteLine("Code: {0}", ex.Detail.ErrorCode);
                Debug.WriteLine("Message: {0}", ex.Detail.Message);
                Debug.WriteLine("Plugin Trace: {0}", ex.Detail.TraceText);
                Debug.WriteLine("Inner Fault: {0}",
                                null == ex.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault");
            }
            catch (System.TimeoutException ex)
            {
                Debug.WriteLine("The application terminated with an error.");
                Debug.WriteLine("Message: {0}", ex.Message);
                Debug.WriteLine("Stack Trace: {0}", ex.StackTrace);
                Debug.WriteLine("Inner Fault: {0}",
                                null == ex.InnerException.Message ? "No Inner Fault" : ex.InnerException.Message);
            }
            catch (System.Exception ex)
            {
                Debug.WriteLine("The application terminated with an error.");
                Debug.WriteLine(ex.Message);

                // Display the details of the inner exception.
                if (ex.InnerException != null)
                {
                    Debug.WriteLine(ex.InnerException.Message);

                    FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> fe = ex.InnerException
                                                                                     as FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault>;
                    if (fe != null)
                    {
                        Console.WriteLine("Timestamp: {0}", fe.Detail.Timestamp);
                        Console.WriteLine("Code: {0}", fe.Detail.ErrorCode);
                        Console.WriteLine("Message: {0}", fe.Detail.Message);
                        Console.WriteLine("Plugin Trace: {0}", fe.Detail.TraceText);
                        Console.WriteLine("Inner Fault: {0}",
                                          null == fe.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault");
                    }
                }
            }
            // Additional exceptions to catch: SecurityTokenValidationException, ExpiredSecurityTokenException,
            // SecurityAccessDeniedException, MessageSecurityException, and SecurityNegotiationException.

            finally
            {
                Debug.WriteLine("Press <Enter> to exit.");
            }
        }
Beispiel #7
0
        public ActionResult Create(CRMContact cRMContact)
        {
            if (ModelState.IsValid)
            {
                cRMContact.CreatedByUserId = WebUser.Id;

                _crmContactRepository.Create(cRMContact);
                _unitOfWork.Commit();

                return(RedirectToAction("Index"));
            }

            return(View(cRMContact));
        }
        public CRMContact Put(CRMContact contact)
        {
            var t = Get(contact.Id);

            if (t == null)
            {
                throw new Exception(string.Format("Contact with id {0} not exists.", contact.Id));
            }

            /*
             * t.Description = contact.Description;
             * t.Priority = contact.Priority;
             */
            return(t);
        }
 public CRMPotentialDetailsViewModel(CRMPotential potential)
 {
     Id                = potential.Id;
     CategoryId        = potential.CategoryId;
     Category          = potential.Category;
     ExpectedAmount    = potential.ExpectedAmount;
     ExpectedCloseDate = potential.ExpectedCloseDate;
     Description       = potential.Description;
     EnquiredOn        = potential.EnquiredOn;
     SalesStageId      = potential.SalesStageId;
     SalesStage        = potential.SalesStage;
     AssignedToUserId  = potential.AssignedToUserId;
     AssignedToUser    = potential.AssignedToUser;
     ContactId         = potential.ContactId;
     Contact           = potential.Contact;
 }
Beispiel #10
0
 public IHttpActionResult Post(CRMContact crmContact)
 {
     if (ModelState.IsValid)
     {
         int c = _objContactBll.Insert(crmContact);
         if (c == 1)
         {
             return(Json(new { Msg = "1" }));
         }
         return(Json(new { Msg = "0" }));
     }
     else
     {
         return(Json(new { Msg = "0" }));
     }
 }
Beispiel #11
0
        public ActionResult Edit(int id = 0)
        {
            BindAccountNames();
            BindDevelopers();
            BindAccountTypes();
            BindAccountManager();
            BindCity();
            BindAccountMasterStatus();

            CRMContact crmcontact = db.CRMContact.Find(id);

            if (crmcontact == null)
            {
                return(HttpNotFound());
            }
            return(View(crmcontact));
        }
Beispiel #12
0
        public ActionResult Edit(CRMContact cRMContact)
        {
            if (ModelState.IsValid)
            {
                var selectedContact = _crmContactRepository.GetBy(l => l.Id == cRMContact.Id);

                if (selectedContact != null)
                {
                    selectedContact.ParentAccountId             = cRMContact.ParentAccountId;
                    selectedContact.Person.FirstName            = cRMContact.Person.FirstName;
                    selectedContact.Person.LastName             = cRMContact.Person.LastName;
                    selectedContact.Person.Gender               = cRMContact.Person.Gender;
                    selectedContact.Person.Email                = cRMContact.Person.Email;
                    selectedContact.Person.Organization         = cRMContact.Person.Organization;
                    selectedContact.Person.Designation          = cRMContact.Person.Designation;
                    selectedContact.Person.PhoneNo              = cRMContact.Person.PhoneNo;
                    selectedContact.Person.SecondaryEmail       = cRMContact.Person.SecondaryEmail;
                    selectedContact.Person.OfficePhone          = cRMContact.Person.OfficePhone;
                    selectedContact.Person.Website              = cRMContact.Person.Website;
                    selectedContact.Person.Skype                = cRMContact.Person.Skype;
                    selectedContact.Person.Facebook             = cRMContact.Person.Facebook;
                    selectedContact.Person.Twitter              = cRMContact.Person.Twitter;
                    selectedContact.Person.GooglePlus           = cRMContact.Person.GooglePlus;
                    selectedContact.Person.LinkedIn             = cRMContact.Person.LinkedIn;
                    selectedContact.Person.City                 = cRMContact.Person.City;
                    selectedContact.Person.Country              = cRMContact.Person.Country;
                    selectedContact.Person.Address              = cRMContact.Person.Address;
                    selectedContact.Person.CommunicationAddress = cRMContact.Person.CommunicationAddress;
                    selectedContact.Person.DateOfBirth          = cRMContact.Person.DateOfBirth;
                    selectedContact.Expertise = cRMContact.Expertise;
                    selectedContact.Comments  = cRMContact.Comments;

                    selectedContact.UpdatedByUserId = WebUser.Id;

                    _crmContactRepository.Update(selectedContact);
                    _unitOfWork.Commit();

                    return(RedirectToAction("Index"));
                }
            }

            return(View(cRMContact));
        }
Beispiel #13
0
        public ActionResult Edit(int id = 0)
        {
            BindTypeofconversations();
            BindReferralSources();
            BindAccountNames();
            BindDevelopers();
            BindAccountTypes();
            BindAccountManager();
            BindCity();
            BindContactStatus();
            BindFollowUpHH();
            BindFollowUpMM();
            CRMContact crmcontact = db.CRMContact.Find(id);

            if (crmcontact == null)
            {
                return(HttpNotFound());
            }
            return(View(crmcontact));
        }
Beispiel #14
0
        public CRMContactModel(CRMContact contact)
        {
            Id = contact.Id;

            if (contact.ParentAccount != null)
            {
                ParentAccount = contact.ParentAccount.Title;
            }

            if (contact.Person != null)
            {
                Name = contact.Person.Name;
            }

            PhoneNo         = contact.Person.PhoneNo;
            Email           = contact.Person.Email;
            CreatedOn       = contact.CreatedOn;
            Organization    = contact.Person.Organization;
            Gender          = contact.Person.Gender;
            ParentAccountId = contact.ParentAccountId;
            PersonId        = contact.PersonId;
            Designation     = contact.Person.Designation;
            SecondaryEmail  = contact.Person.SecondaryEmail;
            OfficePhone     = contact.Person.OfficePhone;
            Website         = contact.Person.Website;
            Skype           = contact.Person.Skype;
            Facebook        = contact.Person.Facebook;
            //Status = GetEnumDescription(employee.EmployeeStatus);
            LinkedIn             = contact.Person.LinkedIn;
            Twitter              = contact.Person.Twitter;
            Country              = contact.Person.Country;
            GooglePlus           = contact.Person.GooglePlus;
            City                 = contact.Person.City;
            FirstName            = contact.Person.FirstName;
            LastName             = contact.Person.LastName;
            Address              = contact.Person.Address;
            CommunicationAddress = contact.Person.CommunicationAddress;
            DateOfBirth          = contact.Person.DateOfBirth;
            Comments             = contact.Comments;
            Expertise            = contact.Expertise;
        }
Beispiel #15
0
        //联络人信息要保存历史记录
        public CRMContact Save(CRMContact entity)
        {
            if (this.dataCtx.Connection != null)
            {
                if (this.dataCtx.Connection.State == ConnectionState.Closed)
                {
                    this.dataCtx.Connection.Open();
                }
            }
            DbTransaction tran = this.dataCtx.Connection.BeginTransaction();

            dataCtx.Transaction = tran;

            try
            {
                var qry = from t in CRMContacts
                          where t.ContactID == entity.ContactID
                          select t;
                var obj = qry.SingleOrDefault();
                if (obj != null)
                {
                    //this.CopyEntity(obj, entity);
                    obj.IsActive = false;   //把原来的联络人信息的IsActive=false
                }
                this.CRMContacts.InsertOnSubmit(entity);

                this.dataCtx.SubmitChanges();
                tran.Commit();
                return(entity);
            }
            catch (Exception ex)
            {
                tran.Rollback();
                throw ex;
            }
            finally
            {
                dataCtx.Connection.Close();
            }
        }
Beispiel #16
0
        public async Task getCRMContact()
        {
            if (MessagesController.LocalUser != null)
            {
                HttpClient cons = new HttpClient();
                cons.BaseAddress = new Uri("");
                cons.DefaultRequestHeaders.Accept.Clear();
                cons.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                using (cons)
                {
                    HttpResponseMessage res = await cons.GetAsync("CRM/GetContact/'" + MessagesController.LocalUser.AADEmail.ToString() + "'/");

                    if (res.IsSuccessStatusCode)
                    {
                        CRMContact contact = await res.Content.ReadAsAsync <CRMContact>();

                        MessagesController.LocalUser.CRMContactId = contact.ContactId;
                    }
                }
            }
        }
Beispiel #17
0
        public async Task getCRMContact()
        {
            if (MessagesController.ConverastionalUserList != null)
            {
                HttpClient cons = new HttpClient();
                cons.BaseAddress = new Uri("https://crmapikyliebot.azurewebsites.net/");
                cons.DefaultRequestHeaders.Accept.Clear();
                cons.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                cons.Timeout = TimeSpan.FromMinutes(1);

                using (cons)
                {
                    HttpResponseMessage res = await cons.GetAsync("CRM/GetContact/'" + MessagesController.ConverastionalUserList[index].AADEmail.ToString() + "'/");

                    if (res.IsSuccessStatusCode)
                    {
                        CRMContact contact = await res.Content.ReadAsAsync <CRMContact>();

                        MessagesController.ConverastionalUserList[index].CRMContactId = contact.ContactId;
                    }
                }
            }
        }
Beispiel #18
0
        public IHttpActionResult UpdateContact(int Id, CRMContact crmContact)
        {
            if (!ModelState.IsValid)
            {
                //return BadRequest(ModelState);
                return(Json(new { Msg = "0" }));
            }

            if (Id != crmContact.ContactID)
            {
                //return BadRequest();
                return(Json(new { Msg = "0" }));
            }

            try
            {
                int s = _objContactBll.Update(crmContact);
                if (s == 1)
                {
                    return(Json(new { Msg = "1" }));
                }
                return(Json(new { Msg = "0" }));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ContactExists(Id))
                {
                    //return NotFound();
                    return(Json(new { Msg = "0", Reason = "No row affected!" }));
                }
                else
                {
                    throw;
                }
            }
        }
Beispiel #19
0
        public bool Convert(bool createAccount, bool createPotential, int id, int assignedToUserId, int?categoryId, double?expectedAmount, DateTime?expectedCloseDate, string description, DateTime?enquiredOn, int salesStage, int createdByUserId)
        {
            var selectedLead = _crmLeadRepository.GetBy(l => l.Id == id, "Person");

            if (selectedLead != null)
            {
                CRMAccount selectedOrganization = null;

                if (createAccount)
                {
                    // Create the Account First
                    var organization = selectedLead.Person.Organization;

                    if (!string.IsNullOrEmpty(organization))
                    {
                        selectedOrganization = _crmAccountRepository.GetBy(a => a.Title == organization);
                        if (selectedOrganization == null)
                        {
                            selectedOrganization = new CRMAccount
                            {
                                Title                = organization,
                                EmployeeCount        = EmployeeCount.One2Ten,
                                AssignedToEmployeeId = assignedToUserId,
                                CreatedByUserId      = createdByUserId
                            };

                            _crmAccountRepository.Create(selectedOrganization);
                            _unitOfWork.Commit();
                        }
                    }
                }

                // Create Contact
                var contact = new CRMContact
                {
                    PersonId        = selectedLead.PersonId,
                    CreatedByUserId = createdByUserId
                };

                // Assign the account Id
                if (selectedOrganization != null)
                {
                    contact.ParentAccountId = selectedOrganization.Id;
                }

                _crmContactRepository.Create(contact);
                _unitOfWork.Commit();

                if (createPotential)
                {
                    // Create the Potential
                    var potential = new CRMPotential
                    {
                        CategoryId        = categoryId,
                        ExpectedAmount    = expectedAmount,
                        ExpectedCloseDate = expectedCloseDate,
                        Description       = description,
                        EnquiredOn        = enquiredOn,
                        SalesStageId      = salesStage,
                        AssignedToUserId  = assignedToUserId,
                        ContactId         = contact.Id,
                        CreatedByUserId   = createdByUserId
                    };

                    _crmPotentialRepository.Create(potential);
                    _unitOfWork.Commit();

                    // Move all Lead Technologies to Potential Technologies
                    var technologies = _crmLeadTechnologyMapRepository.GetAllBy(m => m.LeadId == selectedLead.Id).ToList();
                    foreach (var technology in technologies)
                    {
                        var technologyMap = new CRMPotentialTechnologyMap
                        {
                            PotentialId  = potential.Id,
                            TechnologyId = technology.TechnologyId
                        };

                        _crmPotentialTechnologyMapRepository.Create(technologyMap);
                    }

                    // Move all Lead Activities to Potential Activities
                    var activities = _crmLeadActivityRepository.GetAllBy(m => m.CRMLeadId == selectedLead.Id).ToList();
                    foreach (var activity in activities)
                    {
                        var potentialActivity = new CRMPotentialActivity
                        {
                            CRMPotentialId  = potential.Id,
                            Title           = activity.Title,
                            Comment         = activity.Comment,
                            CreatedOn       = activity.CreatedOn,
                            CreatedByUserId = createdByUserId
                        };

                        _crmPotentialActivityRepository.Create(potentialActivity);
                    }

                    _unitOfWork.Commit();
                }

                // Delete the Lead
                _crmLeadService.Delete(id);

                return(true);
            }

            return(false);
        }
Beispiel #20
0
        public ActionResult Update(CRMContactModel cRMContact)
        {
            ApiResult <CRMContact> apiResult;

            if (ModelState.IsValid)
            {
                if (cRMContact.Id > 0)
                {
                    apiResult = TryExecute(() =>
                    {
                        var person = _personRepository.GetBy(l => l.Id == cRMContact.PersonId);
                        if (person != null)
                        {
                            person.Id                   = cRMContact.PersonId;
                            person.FirstName            = cRMContact.FirstName;
                            person.LastName             = cRMContact.LastName;
                            person.Gender               = cRMContact.Gender;
                            person.Email                = cRMContact.Email;
                            person.Organization         = cRMContact.Organization;
                            person.Designation          = cRMContact.Designation;
                            person.PhoneNo              = cRMContact.PhoneNo;
                            person.SecondaryEmail       = cRMContact.SecondaryEmail;
                            person.OfficePhone          = cRMContact.OfficePhone;
                            person.Website              = cRMContact.Website;
                            person.Skype                = cRMContact.Skype;
                            person.Facebook             = cRMContact.Facebook;
                            person.Twitter              = cRMContact.Twitter;
                            person.GooglePlus           = cRMContact.GooglePlus;
                            person.LinkedIn             = cRMContact.LinkedIn;
                            person.City                 = cRMContact.City;
                            person.Country              = cRMContact.Country;
                            person.Address              = cRMContact.Address;
                            person.CommunicationAddress = cRMContact.CommunicationAddress;
                            person.DateOfBirth          = cRMContact.DateOfBirth;
                            _personRepository.Update(person);
                            _unitOfWork.Commit();
                        }


                        var selectedContact = _crmContactRepository.GetBy(l => l.Id == cRMContact.Id);
                        if (selectedContact != null)
                        {
                            selectedContact.ParentAccountId = cRMContact.ParentAccountId;
                            selectedContact.Expertise       = cRMContact.Expertise;
                            selectedContact.Comments        = cRMContact.Comments;
                            selectedContact.UpdatedByUserId = WebUser.Id;

                            _crmContactRepository.Update(selectedContact);
                            _unitOfWork.Commit();
                        }
                        return(selectedContact);
                    }, "Contact updated sucessfully");
                }
                else
                {
                    apiResult = TryExecute(() =>
                    {
                        var newPerson = new Person
                        {
                            FirstName            = cRMContact.FirstName,
                            LastName             = cRMContact.LastName,
                            Gender               = cRMContact.Gender,
                            Email                = cRMContact.Email,
                            Organization         = cRMContact.Organization,
                            Designation          = cRMContact.Designation,
                            PhoneNo              = cRMContact.PhoneNo,
                            SecondaryEmail       = cRMContact.SecondaryEmail,
                            OfficePhone          = cRMContact.OfficePhone,
                            Website              = cRMContact.Website,
                            Skype                = cRMContact.Skype,
                            Facebook             = cRMContact.Facebook,
                            Twitter              = cRMContact.Twitter,
                            GooglePlus           = cRMContact.GooglePlus,
                            LinkedIn             = cRMContact.LinkedIn,
                            City                 = cRMContact.City,
                            Country              = cRMContact.Country,
                            Address              = cRMContact.Address,
                            CommunicationAddress = cRMContact.CommunicationAddress,
                            DateOfBirth          = cRMContact.DateOfBirth,
                        };
                        var person = _personRepository.Create(newPerson);


                        var newContact = new CRMContact
                        {
                            PersonId        = person.Id,
                            ParentAccountId = cRMContact.ParentAccountId,
                            Expertise       = cRMContact.Expertise,
                            Comments        = cRMContact.Comments,
                            CreatedByUserId = WebUser.Id
                        };
                        var contact = _crmContactRepository.Create(newContact);
                        _unitOfWork.Commit();
                        return(newContact);
                    }, "Contact created sucessfully");
                }
            }
            else
            {
                apiResult = ApiResultFromModelErrors <CRMContact>();
            }

            return(Json(apiResult, JsonRequestBehavior.AllowGet));
        }
 // PUT: api/CRMAccount/5
 public void Put(int id, [FromBody] CRMContact account)
 {
 }
 // POST: api/CRMAccount
 public void Post([FromBody] CRMContact account)
 {
     Execute(account);
 }
Beispiel #23
0
        public ActionResult Index(CRMContact crmcontact)
        {
            List <CRMContact> CRMContactList = new List <CRMContact>();

            ViewBag.logged = Session["FullName"];
            var firstdate = DateTime.Now.AddYears(-10);
            var query     = from cr in db.CRMContact
                            where
                            cr.ContactName.Contains(crmcontact.ContactName == null ? cr.ContactName : crmcontact.ContactName) &&
                            cr.DeveloperId == (crmcontact.DeveloperId == 0 ? cr.DeveloperId : crmcontact.DeveloperId) &&
                            cr.ProjectLocationId == (crmcontact.ProjectLocationId == 0 ? cr.ProjectLocationId : crmcontact.ProjectLocationId) &&
                            cr.ContactStatusId == (crmcontact.ContactStatusId == 0 ? cr.ContactStatusId : crmcontact.ContactStatusId) &&
                            (cr.ModifiedDate >= (crmcontact.CreationDate == null ? firstdate : crmcontact.CreationDate) && cr.ModifiedDate <= (crmcontact.CreationDateEnd == null ? DateTime.Now : crmcontact.CreationDateEnd))
                            join cs in db.ContactStatus on cr.ContactStatusId equals cs.ContactStatusId
                            join dp in db.DeveloperMaster on cr.DeveloperId equals dp.DeveloperId
                            join amm in db.SignUp on cr.AccountManagerId equals amm.SignUpId
                            join ct in db.City on cr.ProjectLocationId equals ct.CityID
                            join acty in db.AccountTypeMaster on cr.AccountTypeId equals acty.AccountTypeId
                            join actnm in db.AccountMaster on cr.AccountMasterId equals actnm.AccountMasterId
                            join cust in db.Customers on cr.ContactId equals cust.Contid into gj
                            from subpet in gj.DefaultIfEmpty()
                            select new
            {
                ContactId           = cr.ContactId,
                ContactName         = cr.ContactName,
                ContactStatusName   = (cr.ContactStatusId == 0 ? String.Empty : cs.ContactStatusName),
                DeveloperName       = (cr.DeveloperId == 0 ? String.Empty : dp.DeveloperName),
                ProjectLocationCity = (cr.ProjectLocationId == 0 ? String.Empty : ct.CityName),
                AccountManagerName  = (cr.AccountManagerId == 0 ? String.Empty : amm.FullName),
                Address             = cr.Address,
                AccountTypeName     = (cr.AccountTypeId == 0 ? String.Empty : acty.AccountTypeName),
                CreationDate        = cr.ModifiedDate,
                AccountMasterName   = (cr.AccountMasterId == 0 ? String.Empty : actnm.AccountMasterName),
                MobileNumber        = cr.MobileNumber,
                PhoneNumber         = cr.PhoneNumber,
                Budget   = cr.Budget,
                IsActive = (subpet.IsActive == null ? false : true),
            };

            var CRMContacts = query.ToList();

            foreach (var CRMContactsData in CRMContacts)
            {
                CRMContactList.Add(new CRMContact()
                {
                    ContactName         = CRMContactsData.ContactName.ToString(),
                    ContactStatusName   = CRMContactsData.ContactStatusName.ToString(),
                    ContactId           = CRMContactsData.ContactId,
                    DeveloperName       = CRMContactsData.DeveloperName.ToString(),
                    ProjectLocationCity = CRMContactsData.ProjectLocationCity.ToString(),
                    AccountManagerName  = CRMContactsData.AccountManagerName.ToString(),
                    Address             = CRMContactsData.Address.ToString(),
                    AccountTypeName     = CRMContactsData.AccountTypeName.ToString(),
                    CreationDate        = CRMContactsData.CreationDate,
                    AccountMasterName   = CRMContactsData.AccountMasterName.ToString(),
                    MobileNumber        = CRMContactsData.MobileNumber.ToString(),
                    PhoneNumber         = CRMContactsData.PhoneNumber.ToString(),
                    Budget   = CRMContactsData.Budget.ToString(),
                    IsActive = CRMContactsData.IsActive,
                });
            }
            BindAccountNames();
            BindDevelopersForIndex();
            BindAccountTypes();
            BindAccountManager();
            BindCity();
            BindContactStatus();
            ViewBag.CRMContactList = CRMContactList;
            ModelState.Clear();
            return(View());
        }
        public static string GetProfileImage(CRMContact crmContact)
        {
            if (crmContact.CRMFuneralHome.WebsiteProvider == Models.Data.Enums.WebsiteProvider.FuneralNet)
            {
                string aboutPage       = crmContact.CRMFuneralHome.Website + "/_mgxroot/page_10721.php";
                var    pedersenPage    = new HtmlWeb();
                var    document        = pedersenPage.Load(aboutPage);
                string searchText      = "//h3[contains(text(), '" + crmContact.FirstName + " " + crmContact.LastName + "')]";
                var    funeralHomeNode = document.DocumentNode.SelectNodes(searchText);
                if (funeralHomeNode != null)
                {
                    string imagePath = "";
                    foreach (var node in funeralHomeNode)
                    {
                        if (node.NextSibling.NextSibling.Name == "h4")
                        {
                            try
                            {
                                imagePath = node.NextSibling.NextSibling.ChildNodes.Where(n => n.Name == "img").FirstOrDefault().Attributes.Where(a => a.Name == "src").FirstOrDefault().Value;
                                imagePath = crmContact.CRMFuneralHome.Website + "/_mgxroot/" + imagePath;
                                return(imagePath);
                            }
                            catch
                            {
                            }
                        }
                        else
                        {
                            if (node.NextSibling.NextSibling.Name == "p")
                            {
                                try
                                {
                                    if (node.NextSibling.NextSibling.ChildNodes.Where(n => n.Name == "font").FirstOrDefault() != null)
                                    {
                                        var shouldBeFontNode = node.NextSibling.NextSibling.ChildNodes.Where(n => n.Name == "font").FirstOrDefault();
                                        if (shouldBeFontNode != null)
                                        {
                                            var shouldBeStrongNode = shouldBeFontNode.ChildNodes.Where(n => n.Name == "strong").FirstOrDefault();
                                            if (shouldBeStrongNode != null)
                                            {
                                                imagePath = shouldBeStrongNode.ChildNodes.Where(c => c.Name == "img").FirstOrDefault().Attributes.Where(a => a.Name == "src").FirstOrDefault().Value;
                                                if (imagePath.Length > 10 && imagePath.Length < 2000)
                                                {
                                                    imagePath = crmContact.CRMFuneralHome.Website + "/_mgxroot/" + imagePath;
                                                    return(imagePath);
                                                }
                                            }
                                        }
                                    }
                                }
                                catch
                                {
                                }
                                try
                                {
                                    if (node.NextSibling.NextSibling.ChildNodes.Where(n => n.Name == "img").FirstOrDefault() != null)
                                    {
                                        imagePath = node.NextSibling.NextSibling.ChildNodes.Where(n => n.Name == "img").FirstOrDefault().Attributes.Where(a => a.Name == "src").FirstOrDefault().Value;
                                        if (imagePath.Length > 10 && imagePath.Length < 2000)
                                        {
                                            imagePath = crmContact.CRMFuneralHome.Website + "/_mgxroot/" + imagePath;
                                            return(imagePath);
                                        }
                                    }
                                }
                                catch
                                {
                                }
                            }
                        }
                    }
                }
            }
            if (crmContact.CRMFuneralHome.WebsiteProvider == Models.Data.Enums.WebsiteProvider.FuneralOne)
            {
                string aboutPage    = crmContact.CRMFuneralHome.Website + "/who-we-are/our-valued-staff";
                var    aboutWebPage = new HtmlWeb();
                var    document     = aboutWebPage.Load(aboutPage);
                var    images       = document.DocumentNode.Descendants("img").Where(s => s.Attributes.Where(a => a.Name == "src").FirstOrDefault() != null);

                if (images != null)
                {
                    foreach (var image in images)
                    {
                        try
                        {
                            var altTextAttribute = image.Attributes.Where(n => n.Name == "alt").FirstOrDefault();
                            if (altTextAttribute != null)
                            {
                                string altText = altTextAttribute.Value;
                                if (altText.Contains(crmContact.FirstName) && altText.Contains(crmContact.LastName))
                                {
                                    var imagePath = image.Attributes.Where(s => s.Name == "src").FirstOrDefault().Value;
                                    return("http://" + imagePath);
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                }
            }
            return("");
        }
Beispiel #25
0
        public ActionResult ViewContact(int id = 0)
        {
            BindTypeofconversations();
            BindReferralSources();
            BindAccountNames();
            BindDevelopers();
            BindAccountTypes();
            BindAccountManager();
            BindCity();
            BindContactStatus();
            BindFollowUpHH();
            BindFollowUpMM();

            List <FollowAlerts> FollowAlertList = new List <FollowAlerts>();
            var quryalerts =
                from fa in db.FollowAlerts
                where fa.ContactId == id
                join typcon in db.Typeofconversations on fa.TypeofconversationId equals typcon.TypeofconversationId
                select new
            {
                AlertId                = fa.AlertId,
                Comments               = fa.Comments,
                FollowUpDate           = fa.FollowUpDate,
                FollowUpHH             = fa.FollowUpHH,
                FollowUpMM             = fa.FollowUpMM,
                FollowUpAMPM           = fa.FollowUpAMPM,
                RemindMe2Hours         = fa.RemindMe2Hours,
                RemindMeToDay          = fa.RemindMeToDay,
                RemindMe2Days          = fa.RemindMe2Days,
                Status                 = fa.Status,
                ContactId              = fa.ContactId,
                TypeofconversationName = typcon.TypeofconversationName
            };

            var FollowAlerts = quryalerts.ToList();

            foreach (var FollowAlertsData in FollowAlerts)
            {
                FollowAlertList.Add(new FollowAlerts()
                {
                    AlertId                = FollowAlertsData.AlertId,
                    Comments               = FollowAlertsData.Comments,
                    FollowUpDate           = FollowAlertsData.FollowUpDate,
                    FollowUpHH             = FollowAlertsData.FollowUpHH + ':' + FollowAlertsData.FollowUpMM + FollowAlertsData.FollowUpAMPM,
                    RemindMe2Hours         = FollowAlertsData.RemindMe2Hours,
                    RemindMeToDay          = FollowAlertsData.RemindMeToDay,
                    RemindMe2Days          = FollowAlertsData.RemindMe2Days,
                    Status                 = FollowAlertsData.Status,
                    ContactId              = FollowAlertsData.ContactId,
                    TypeofconversationName = FollowAlertsData.TypeofconversationName,
                });
            }

            ViewBag.FollowAlerts = FollowAlertList;
            var query = (from cr in db.CRMContact
                         where cr.ContactId == id
                         join cs in db.ContactStatus on cr.ContactStatusId equals cs.ContactStatusId
                         join dp in db.DeveloperMaster on cr.DeveloperId equals dp.DeveloperId
                         join amm in db.SignUp on cr.AccountManagerId equals amm.SignUpId
                         join ct in db.City on cr.ProjectLocationId equals ct.CityID
                         join acty in db.AccountTypeMaster on cr.AccountTypeId equals acty.AccountTypeId
                         join actnm in db.AccountMaster on cr.AccountMasterId equals actnm.AccountMasterId
                         join refs in db.ReferralSources on cr.ReferralSourceId equals refs.ReferralSourceId
                         select new
            {
                ContactId = cr.ContactId,
                ContactName = cr.ContactName,
                ContactEmailAddress = cr.ContactEmailAddress,
                ContactStatusName = (cr.ContactStatusId == 0 ? String.Empty : cs.ContactStatusName),
                DeveloperName = (cr.DeveloperId == 0 ? String.Empty : dp.DeveloperName),
                OtherDeveloperName = cr.OtherDeveloperName,
                ProjectLocationCity = (cr.ProjectLocationId == 0 ? String.Empty : ct.CityName),
                AccountManagerName = (cr.AccountManagerId == 0 ? String.Empty : amm.FullName),
                Address = cr.Address,
                AccountTypeName = (cr.AccountTypeId == 0 ? String.Empty : acty.AccountTypeName),
                CreationDate = cr.ModifiedDate,
                AccountMasterName = (cr.AccountMasterId == 0 ? String.Empty : actnm.AccountMasterName),
                OtherAccountName = cr.OtherAccountName,
                MobileNumber = cr.MobileNumber,
                PhoneNumber = cr.PhoneNumber,
                Budget = cr.Budget,
                ReferralSourceName = (cr.ReferralSourceId == 0 ? String.Empty : refs.ReferralSourceName),
            }).FirstOrDefault();

            if (query != null)
            {
                CRMContact crmContact = new CRMContact()
                {
                    ContactName         = query.ContactName,
                    ContactEmailAddress = query.ContactEmailAddress,
                    ContactStatusName   = query.ContactStatusName,
                    ContactId           = query.ContactId,
                    DeveloperName       = query.DeveloperName,
                    OtherDeveloperName  = query.OtherDeveloperName,
                    ProjectLocationCity = query.ProjectLocationCity,
                    AccountManagerName  = query.AccountManagerName,
                    Address             = query.Address,
                    AccountTypeName     = query.AccountTypeName,
                    CreationDate        = query.CreationDate,
                    AccountMasterName   = query.AccountMasterName,
                    OtherAccountName    = query.OtherAccountName,
                    MobileNumber        = query.MobileNumber,
                    PhoneNumber         = query.PhoneNumber,
                    Budget             = query.Budget,
                    ReferralSourceName = query.ReferralSourceName,
                };
                return(View(crmContact));
            }
            else
            {
                return(HttpNotFound());
            }
        }
        public static string GetDescription(CRMContact crmContact)
        {
            if (crmContact.CRMFuneralHome.WebsiteProvider == Models.Data.Enums.WebsiteProvider.FuneralNet)
            {
                string aboutPage       = crmContact.CRMFuneralHome.Website + "/_mgxroot/page_10721.php";
                var    pedersenPage    = new HtmlWeb();
                var    document        = pedersenPage.Load(aboutPage);
                string searchText      = "//h3[contains(text(), '" + crmContact.FirstName + " " + crmContact.LastName + "')]";
                var    funeralHomeNode = document.DocumentNode.SelectNodes(searchText);
                if (funeralHomeNode != null)
                {
                    string descrip = "";
                    foreach (var node in funeralHomeNode)
                    {
                        try
                        {
                            descrip = node.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
                            if (node.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.Name == "p")
                            {
                                if (node.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText.Length > 10)
                                {
                                    descrip = descrip + "<br/>" + node.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
                                }
                                if (node.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.Name == "p")
                                {
                                    if (node.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText.Length > 10)
                                    {
                                        descrip = descrip + "<br/>" + node.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
                                    }
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                    if (descrip.Length > 10 && descrip.Length < 2000)
                    {
                        if (descrip.Contains("&nbsp;"))
                        {
                            int nbspLoc = descrip.IndexOf("&nbsp;");
                            descrip = descrip.Remove(nbspLoc, 6);
                        }
                        return(descrip);
                    }
                }
            }
            if (crmContact.CRMFuneralHome.WebsiteProvider == Models.Data.Enums.WebsiteProvider.FuneralOne)
            {
                string aboutPage    = crmContact.CRMFuneralHome.Website + "/who-we-are/our-valued-staff";
                var    aboutWebPage = new HtmlWeb();
                var    document     = aboutWebPage.Load(aboutPage);;
                var    h4Nodes      = document.DocumentNode.Descendants("h4").ToList();
                if (h4Nodes != null)
                {
                    string descrip = "";
                    foreach (var node in h4Nodes)
                    {
                        if (node.InnerText.Contains(crmContact.FirstName) && node.InnerText.Contains(crmContact.LastName))
                        {
                            descrip = node.NextSibling.NextSibling.InnerText;
                            if (descrip.Length > 10 && descrip.Length < 1800)
                            {
                                return(descrip);
                            }
                        }
                    }
                    return("");
                }
            }
            if (crmContact.CRMFuneralHome.WebsiteProvider == Models.Data.Enums.WebsiteProvider.Batesville)
            {
                string homePage = crmContact.CRMFuneralHome.Website;
                var    homeWeb  = new HtmlWeb();
                var    document = homeWeb.Load(homePage);

                var h4Nodes = document.DocumentNode.Descendants("h4").ToList();
            }
            return("");
        }
Beispiel #27
0
        public ActionResult Edit(CRMContact crmcontact)
        {
            if (ModelState.IsValid)
            {
                string sqlqry = "UPDATE CRMContacts SET ContactName=@ContactName ,AccountMasterId=@AccountMasterId ,DeveloperId=@DeveloperId ,AccountTypeId=@AccountTypeId ,ProjectLocationId=@ProjectLocationId ,Address=@Address ,PhoneNumber=@PhoneNumber ,";
                sqlqry += "AccountManagerId=@AccountManagerId ,ContactStatusId=@ContactStatusId ,Budget=@Budget,ReferralSourceId=@ReferralSourceId,TypeofconversationId=@TypeofconversationId ,ModifiedBy=@ModifiedBy,ModifiedDate=@ModifiedDate";
                sqlqry += " Where ContactId=@ContactId";
                List <SqlParameter> parameterList = new List <SqlParameter>();
                parameterList.Add(new SqlParameter("@ContactId", crmcontact.ContactId));
                parameterList.Add(new SqlParameter("@ContactName", crmcontact.ContactName));
                parameterList.Add(new SqlParameter("@AccountMasterId", crmcontact.AccountMasterId));
                parameterList.Add(new SqlParameter("@DeveloperId", crmcontact.DeveloperId));
                parameterList.Add(new SqlParameter("@AccountTypeId", crmcontact.AccountTypeId));
                parameterList.Add(new SqlParameter("@ProjectLocationId", crmcontact.ProjectLocationId));
                parameterList.Add(new SqlParameter("@Address", crmcontact.Address));
                parameterList.Add(new SqlParameter("@PhoneNumber", crmcontact.PhoneNumber));
                parameterList.Add(new SqlParameter("@AccountManagerId", crmcontact.AccountManagerId));
                parameterList.Add(new SqlParameter("@ContactStatusId", crmcontact.ContactStatusId));
                parameterList.Add(new SqlParameter("@Budget", crmcontact.Budget));
                parameterList.Add(new SqlParameter("@ReferralSourceId", crmcontact.ReferralSourceId));
                parameterList.Add(new SqlParameter("@TypeofconversationId", crmcontact.TypeofconversationId));
                parameterList.Add(new SqlParameter("@ModifiedBy", 1));
                parameterList.Add(new SqlParameter("@ModifiedDate", DateTime.Now));

                SqlParameter[] parameters = parameterList.ToArray();
                int            result     = (int)db.Database.ExecuteSqlCommand(sqlqry, parameters);
                if (result != null)
                {
                    if (crmcontact.FollowUpDate != null)
                    {
                        /////--------Insert Data in FollowAlerts---///
                        string sqlqry2 = "INSERT INTO FollowAlerts(ContactId,Comments ,FollowUpDate,FollowUpHH,FollowUpMM,FollowUpAMPM,RemindMe2Hours,RemindMeToDay,RemindMe2Days,Status)";
                        sqlqry2 += "Values(@ContactId,@Comments ,@FollowUpDate,@FollowUpHH,@FollowUpMM,@FollowUpAMPM,@RemindMe2Hours,@RemindMeToDay,@RemindMe2Days,@Status)";
                        List <SqlParameter> parameterList2 = new List <SqlParameter>();
                        parameterList2.Add(new SqlParameter("@ContactId", crmcontact.ContactId));
                        parameterList2.Add(new SqlParameter("@Comments", crmcontact.Comments));
                        parameterList2.Add(new SqlParameter("@FollowUpDate", crmcontact.FollowUpDate));
                        parameterList2.Add(new SqlParameter("@FollowUpHH", crmcontact.FollowUpHH));
                        parameterList2.Add(new SqlParameter("@FollowUpMM", crmcontact.FollowUpMM));
                        parameterList2.Add(new SqlParameter("@FollowUpAMPM", crmcontact.FollowUpAMPM));
                        parameterList2.Add(new SqlParameter("@RemindMe2Hours", crmcontact.RemindMe2Hours));
                        parameterList2.Add(new SqlParameter("@RemindMeToDay", crmcontact.RemindMeToDay));
                        parameterList2.Add(new SqlParameter("@RemindMe2Days", crmcontact.RemindMe2Days));
                        parameterList2.Add(new SqlParameter("@Status", 1));//1 for yes and 2 no//
                        SqlParameter[] parameters2 = parameterList2.ToArray();
                        int            result2     = db.Database.ExecuteSqlCommand(sqlqry2, parameters2);
                    }
                }
                return(RedirectToAction("ViewContact", "CRM", new { id = crmcontact.ContactId }));
            }


            BindAccountNames();
            BindDevelopers();
            BindAccountTypes();
            BindAccountManager();
            BindCity();
            BindAccountMasterStatus();

            return(View(crmcontact));
        }
Beispiel #28
0
        public ActionResult Edit(CRMContact crmcontact)
        {
            //var user = db.CRMContact.Where(u => u.ContactEmailAddress == crmcontact.ContactEmailAddress).FirstOrDefault();
            //if (user == null)
            //{
            //    var ckmobile = db.CRMContact.Where(u => u.MobileNumber == crmcontact.MobileNumber).FirstOrDefault();
            //    if (ckmobile == null)
            //    {

            if (ModelState.IsValid)
            {
                string sqlqry = "UPDATE CRMContacts SET ContactName=@ContactName ,AccountMasterId=@AccountMasterId,OtherAccountName=@OtherAccountName ,DeveloperId=@DeveloperId,OtherDeveloperName=@OtherDeveloperName,AccountTypeId=@AccountTypeId ,ProjectLocationId=@ProjectLocationId ,Address=@Address ,PhoneNumber=@PhoneNumber ,";
                sqlqry += "AccountManagerId=@AccountManagerId ,ContactStatusId=@ContactStatusId ,Budget=@Budget,ReferralSourceId=@ReferralSourceId ,ModifiedBy=@ModifiedBy,ModifiedDate=@ModifiedDate";
                sqlqry += " Where ContactId=@ContactId";
                List <SqlParameter> parameterList = new List <SqlParameter>();
                parameterList.Add(new SqlParameter("@ContactId", crmcontact.ContactId));
                parameterList.Add(new SqlParameter("@ContactName", crmcontact.ContactName));
                parameterList.Add(new SqlParameter("@AccountMasterId", crmcontact.AccountMasterId));
                parameterList.Add(new SqlParameter("@OtherAccountName", crmcontact.OtherAccountName = crmcontact.OtherAccountName == null ? String.Empty : crmcontact.OtherAccountName));
                parameterList.Add(new SqlParameter("@DeveloperId", crmcontact.DeveloperId));
                parameterList.Add(new SqlParameter("@OtherDeveloperName", crmcontact.OtherDeveloperName = crmcontact.OtherDeveloperName == null ? String.Empty : crmcontact.OtherDeveloperName));
                parameterList.Add(new SqlParameter("@AccountTypeId", crmcontact.AccountTypeId));
                parameterList.Add(new SqlParameter("@ProjectLocationId", crmcontact.ProjectLocationId));
                parameterList.Add(new SqlParameter("@Address", crmcontact.Address));
                parameterList.Add(new SqlParameter("@PhoneNumber", crmcontact.PhoneNumber));
                parameterList.Add(new SqlParameter("@AccountManagerId", crmcontact.AccountManagerId));
                parameterList.Add(new SqlParameter("@ContactStatusId", crmcontact.ContactStatusId));
                parameterList.Add(new SqlParameter("@Budget", crmcontact.Budget));
                parameterList.Add(new SqlParameter("@ReferralSourceId", crmcontact.ReferralSourceId));
                parameterList.Add(new SqlParameter("@ModifiedBy", Session["UserId"]));
                parameterList.Add(new SqlParameter("@ModifiedDate", DateTime.Now));

                SqlParameter[] parameters = parameterList.ToArray();
                int            result     = (int)db.Database.ExecuteSqlCommand(sqlqry, parameters);
                if (result != null)
                {
                    if (crmcontact.FollowUpDate != null)
                    {
                        /////--------Insert Data in FollowAlerts---///
                        string sqlqry2 = "INSERT INTO FollowAlerts(ContactId,Comments ,FollowUpDate,FollowUpHH,FollowUpMM,FollowUpAMPM,RemindMe2Hours,RemindMeToDay,RemindMe2Days,Status,TypeofconversationId)";
                        sqlqry2 += "Values(@ContactId,@Comments ,@FollowUpDate,@FollowUpHH,@FollowUpMM,@FollowUpAMPM,@RemindMe2Hours,@RemindMeToDay,@RemindMe2Days,@Status,@TypeofconversationId)";
                        List <SqlParameter> parameterList2 = new List <SqlParameter>();
                        parameterList2.Add(new SqlParameter("@ContactId", crmcontact.ContactId));
                        parameterList2.Add(new SqlParameter("@Comments", crmcontact.Comments));
                        parameterList2.Add(new SqlParameter("@FollowUpDate", crmcontact.FollowUpDate));
                        parameterList2.Add(new SqlParameter("@FollowUpHH", crmcontact.FollowUpHH));
                        parameterList2.Add(new SqlParameter("@FollowUpMM", crmcontact.FollowUpMM));
                        parameterList2.Add(new SqlParameter("@FollowUpAMPM", crmcontact.FollowUpAMPM));
                        parameterList2.Add(new SqlParameter("@RemindMe2Hours", crmcontact.RemindMe2Hours));
                        parameterList2.Add(new SqlParameter("@RemindMeToDay", crmcontact.RemindMeToDay));
                        parameterList2.Add(new SqlParameter("@RemindMe2Days", crmcontact.RemindMe2Days));
                        parameterList2.Add(new SqlParameter("@Status", 1));                                             //1 for yes and 2 no//
                        parameterList2.Add(new SqlParameter("@TypeofconversationId", crmcontact.TypeofconversationId)); //1 for yes and 2 no//
                        SqlParameter[] parameters2 = parameterList2.ToArray();
                        int            result2     = db.Database.ExecuteSqlCommand(sqlqry2, parameters2);
                    }
                }
                return(RedirectToAction("ViewContact", "CRM", new { id = crmcontact.ContactId }));
            }
            //    }
            //    else
            //    {
            //        ModelState.AddModelError("", "Mobile Number already exists");
            //    }

            //}
            //else
            //{
            //    ModelState.AddModelError("", "Email Address already exists");
            //}

            BindTypeofconversations();
            BindReferralSources();
            BindAccountNames();
            BindDevelopers();
            BindAccountTypes();
            BindAccountManager();
            BindCity();
            BindContactStatus();
            BindFollowUpHH();
            BindFollowUpMM();
            return(View(crmcontact));
        }
Beispiel #29
0
        public ActionResult ViewContact(int id = 0)
        {
            BindAccountNames();
            BindDevelopers();
            BindAccountTypes();
            BindAccountManager();
            BindCity();
            BindAccountMasterStatus();

            ViewBag.FollowAlerts = db.FollowAlerts.SqlQuery("SELECT AlertId ,Comments,FollowUpDate,FollowUpHH,FollowUpMM,FollowUpAMPM,RemindMe2Hours,RemindMeToDay,RemindMe2Days,Status,ContactId FROM FollowAlerts where Contactid=" + id + "").ToList();

            var query = (from cr in db.CRMContact
                         where cr.ContactId == id
                         join cs in db.ContactStatus on cr.ContactStatusId equals cs.ContactStatusId
                         join dp in db.DeveloperMaster on cr.DeveloperId equals dp.DeveloperId
                         join amm in db.AccountManagerMaster on cr.AccountManagerId equals amm.AccountManagerId
                         join ct in db.City on cr.ProjectLocationId equals ct.CityID
                         join acty in db.AccountTypeMaster on cr.AccountTypeId equals acty.AccountTypeId
                         join actnm in db.AccountMaster on cr.AccountMasterId equals actnm.AccountMasterId
                         join refs in db.ReferralSources on cr.ReferralSourceId equals refs.ReferralSourceId
                         join typeconv in db.Typeofconversations on cr.TypeofconversationId equals typeconv.TypeofconversationId
                         select new
            {
                ContactId = cr.ContactId,
                ContactName = cr.ContactName,
                ContactEmailAddress = cr.ContactEmailAddress,
                ContactStatusName = (cr.ContactStatusId == 0 ? String.Empty : cs.ContactStatusName),
                DeveloperName = (cr.DeveloperId == 0 ? String.Empty : dp.DeveloperName),
                ProjectLocationCity = (cr.ProjectLocationId == 0 ? String.Empty : ct.CityName),
                AccountManagerName = (cr.AccountManagerId == 0 ? String.Empty : amm.AccountManagerName),
                Address = cr.Address,
                AccountTypeName = (cr.AccountTypeId == 0 ? String.Empty : acty.AccountTypeName),
                CreationDate = cr.ModifiedDate,
                AccountMasterName = (cr.AccountMasterId == 0 ? String.Empty : actnm.AccountMasterName),
                MobileNumber = cr.MobileNumber,
                PhoneNumber = cr.PhoneNumber,
                Budget = cr.Budget,
                ReferralSourceName = (cr.ReferralSourceId == 0 ? String.Empty : refs.ReferralSourceName),
                TypeofconversationName = (cr.TypeofconversationId == 0 ? String.Empty : typeconv.TypeofconversationName)
            }).FirstOrDefault();

            if (query != null)
            {
                CRMContact crmContact = new CRMContact()
                {
                    ContactName         = query.ContactName,
                    ContactEmailAddress = query.ContactEmailAddress,
                    ContactStatusName   = query.ContactStatusName,
                    ContactId           = query.ContactId,
                    DeveloperName       = query.DeveloperName,
                    ProjectLocationCity = query.ProjectLocationCity,
                    AccountManagerName  = query.AccountManagerName,
                    Address             = query.Address,
                    AccountTypeName     = query.AccountTypeName,
                    CreationDate        = query.CreationDate,
                    AccountMasterName   = query.AccountMasterName,
                    MobileNumber        = query.MobileNumber,
                    PhoneNumber         = query.PhoneNumber,
                    Budget                 = query.Budget,
                    ReferralSourceName     = query.ReferralSourceName,
                    TypeofconversationName = query.TypeofconversationName
                };
                return(View(crmContact));
            }
            else
            {
                return(HttpNotFound());
            }
        }
        private CRMContact GetSaveEntity()
        {
            var entity = new CRMContact();
            if (string.IsNullOrEmpty(txtContactID.Text.Trim()) == false)
                entity.ContactID = int.Parse(txtContactID.Text.Trim());
            if (string.IsNullOrEmpty(txtContactName.Text.Trim()) == false)
                entity.ContactName = txtContactName.Text.Trim();
            if (string.IsNullOrEmpty(txtContactSex.Text.Trim()) == false)
                entity.ContactSex = Boolean.Parse(txtContactSex.Text.Trim());
            if (string.IsNullOrEmpty(txtContactTypeID.Text.Trim()) == false)
                entity.ContactTypeID = int.Parse(txtContactTypeID.Text.Trim());
            if (string.IsNullOrEmpty(txtContactDept.Text.Trim()) == false)
                entity.ContactDept = txtContactDept.Text.Trim();
            if (string.IsNullOrEmpty(txtContactTitle.Text.Trim()) == false)
                entity.ContactTitle = txtContactTitle.Text.Trim();
            if (string.IsNullOrEmpty(txtContactTel.Text.Trim()) == false)
                entity.ContactTel = txtContactTel.Text.Trim();
            if (string.IsNullOrEmpty(txtContactMobile.Text.Trim()) == false)
                entity.ContactMobile = txtContactMobile.Text.Trim();
            if (string.IsNullOrEmpty(txtContactEmail.Text.Trim()) == false)
                entity.ContactEmail = txtContactEmail.Text.Trim();
            if (string.IsNullOrEmpty(txtContactMSN.Text.Trim()) == false)
                entity.ContactMSN = txtContactMSN.Text.Trim();
            if (string.IsNullOrEmpty(txtContactQQ.Text.Trim()) == false)
                entity.ContactQQ = txtContactQQ.Text.Trim();
            if (string.IsNullOrEmpty(txtContactFax.Text.Trim()) == false)
                entity.ContactFax = txtContactFax.Text.Trim();
            if (string.IsNullOrEmpty(txtContactCustID.Text.Trim()) == false)
                entity.ContactCustID = int.Parse(txtContactCustID.Text.Trim());

            entity.IsActive = true;
            return entity;
        }
Beispiel #31
0
        public ActionResult Create(CRMContact crmcontact)
        {
            var user = db.CRMContact.Where(u => u.ContactEmailAddress == crmcontact.ContactEmailAddress).FirstOrDefault();

            if (user == null)
            {
                var ckmobile = db.CRMContact.Where(u => u.MobileNumber == crmcontact.MobileNumber).FirstOrDefault();
                if (ckmobile == null)
                {
                    if (ModelState.IsValid)
                    {
                        string sqlqry = "INSERT INTO CRMContacts (ContactName ,AccountMasterId ,DeveloperId ,AccountTypeId ,ProjectLocationId ,Address ,MobileNumber ,PhoneNumber ,ContactEmailAddress ,AccountManagerId ,ContactStatusId ,Budget,ReferralSourceId,TypeofconversationId ,CreatedBy,CreationDate ,ModifiedBy,ModifiedDate)";
                        sqlqry += " VALUES  (@ContactName ,@AccountMasterId ,@DeveloperId ,@AccountTypeId ,@ProjectLocationId ,@Address ,@MobileNumber ,@PhoneNumber ,@ContactEmailAddress ,@AccountManagerId ,@ContactStatusId ,@Budget,@ReferralSourceId,@TypeofconversationId ,@CreatedBy,@CreationDate ,@ModifiedBy,@ModifiedDate)";

                        List <SqlParameter> parameterList = new List <SqlParameter>();
                        parameterList.Add(new SqlParameter("@ContactName", crmcontact.ContactName));
                        parameterList.Add(new SqlParameter("@AccountMasterId", crmcontact.AccountMasterId));
                        parameterList.Add(new SqlParameter("@DeveloperId", crmcontact.DeveloperId));
                        parameterList.Add(new SqlParameter("@AccountTypeId", crmcontact.AccountTypeId));
                        parameterList.Add(new SqlParameter("@ProjectLocationId", crmcontact.ProjectLocationId));
                        parameterList.Add(new SqlParameter("@Address", crmcontact.Address));
                        parameterList.Add(new SqlParameter("@MobileNumber", crmcontact.MobileNumber));
                        parameterList.Add(new SqlParameter("@PhoneNumber", crmcontact.PhoneNumber));
                        parameterList.Add(new SqlParameter("@ContactEmailAddress", crmcontact.ContactEmailAddress));
                        parameterList.Add(new SqlParameter("@AccountManagerId", crmcontact.AccountManagerId));
                        parameterList.Add(new SqlParameter("@ContactStatusId", crmcontact.ContactStatusId));
                        parameterList.Add(new SqlParameter("@Budget", crmcontact.Budget));
                        parameterList.Add(new SqlParameter("@ReferralSourceId", crmcontact.ReferralSourceId));
                        //parameterList.Add(new SqlParameter("@TypeofconversationId", crmcontact.TypeofconversationId));
                        parameterList.Add(new SqlParameter("@TypeofconversationId", 1));
                        parameterList.Add(new SqlParameter("@CreatedBy", 1));
                        parameterList.Add(new SqlParameter("@CreationDate", DateTime.Now));
                        parameterList.Add(new SqlParameter("@ModifiedBy", 1));
                        parameterList.Add(new SqlParameter("@ModifiedDate", DateTime.Now));

                        SqlParameter[] parameters = parameterList.ToArray();
                        int            result     = (int)db.Database.ExecuteSqlCommand(sqlqry, parameters);
                        if (result != null)
                        {
                            if (crmcontact.FollowUpDate != null)
                            {
                                var checkContacId = from C in db.CRMContact
                                                    where C.ContactEmailAddress == crmcontact.ContactEmailAddress
                                                    select C.ContactId;
                                if (checkContacId.FirstOrDefault() != null)
                                {
                                    int cntid = checkContacId.FirstOrDefault();
                                    /////--------Insert Data in FollowAlerts---///
                                    string sqlqry2 = "INSERT INTO FollowAlerts(ContactId,Comments ,FollowUpDate,FollowUpHH,FollowUpMM,FollowUpAMPM,RemindMe2Hours,RemindMeToDay,RemindMe2Days,Status)";
                                    sqlqry2 += "Values(@ContactId,@Comments ,@FollowUpDate,@FollowUpHH,@FollowUpMM,@FollowUpAMPM,@RemindMe2Hours,@RemindMeToDay,@RemindMe2Days,@Status)";
                                    List <SqlParameter> parameterList2 = new List <SqlParameter>();
                                    parameterList2.Add(new SqlParameter("@ContactId", cntid));
                                    parameterList2.Add(new SqlParameter("@Comments", crmcontact.Comments));
                                    parameterList2.Add(new SqlParameter("@FollowUpDate", crmcontact.FollowUpDate));
                                    parameterList2.Add(new SqlParameter("@FollowUpHH", crmcontact.FollowUpHH));
                                    parameterList2.Add(new SqlParameter("@FollowUpMM", crmcontact.FollowUpMM));
                                    parameterList2.Add(new SqlParameter("@FollowUpAMPM", crmcontact.FollowUpAMPM));
                                    parameterList2.Add(new SqlParameter("@RemindMe2Hours", crmcontact.RemindMe2Hours));
                                    parameterList2.Add(new SqlParameter("@RemindMeToDay", crmcontact.RemindMeToDay));
                                    parameterList2.Add(new SqlParameter("@RemindMe2Days", crmcontact.RemindMe2Days));
                                    parameterList2.Add(new SqlParameter("@Status", 1));//1 for yes and 2 no//
                                    SqlParameter[] parameters2 = parameterList2.ToArray();
                                    int            result2     = db.Database.ExecuteSqlCommand(sqlqry2, parameters2);
                                }
                            }
                        }
                        //db.CRMContact.Add(crmcontact);
                        //db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Mobile Number already exists");
                }
            }
            else
            {
                ModelState.AddModelError("", "Email Address already exists");
            }

            BindAccountNames();
            BindDevelopers();
            BindAccountTypes();
            BindAccountManager();
            BindCity();
            BindAccountMasterStatus();

            return(View(crmcontact));
        }
Beispiel #32
0
 public ActionResult SeacrhContact(CRMContact crmContact)
 {
     return(RedirectToAction("Index", "CRM", crmContact));
 }