Пример #1
0
        /// <summary>
        /// Create a new Lead
        /// </summary>
        /// <param name="createViewModel"></param>
        /// <param name="username">user name, such as type whoami under command line \\F01\anh.tran</param>
        public void CreateLead(LeadModifyViewMode createViewModel, string username)
        {
            try
            {
                var lead = createViewModel.Lead;
                //Svae Address
                _db.CrmLeadAddresses.Add(createViewModel.Address);
                _db.SaveChanges();
                var addressID = createViewModel.Address.AddressID;

                //Save Lead
                lead.AddressID = addressID;
                var emp = new CrmEmployee(username);
                lead.CreatedBy     = emp.UserEmployeeID;
                lead.CreatedAt     = DateTime.Now;
                lead.LastUpdatedBy = emp.UserEmployeeID;
                lead.LastUpdatedAt = DateTime.Now;
                //status
                if (lead.AccountExcutive > 0)
                {
                    lead.AeAssignedAt = DateTime.Now;
                }
                else
                {
                    lead.AeAssignedAt = null;
                }
                _db.CrmLeads.Add(lead);
                _db.SaveChanges();
                LogMethods.Log.Debug("CreateLead:Debug:" + "Done");
            }
            catch (DbEntityValidationException dbEx)
            {
                LogMethods.Log.Error("CreateLead:Error:" + dbEx.Message);
            }
        }
Пример #2
0
        /// <summary>
        /// Edit an existing lead
        /// </summary>
        /// <param name="createViewModel"></param>
        /// <param name="username"></param>
        public void EditLead(LeadModifyViewMode createViewModel, string username)
        {
            var lead = createViewModel.Lead;
            var emp  = new CrmEmployee(username);

            lead.LastUpdatedBy = emp.UserEmployeeID;

            lead.LastUpdatedAt = DateTime.Now;
            var cdt = lead.CriticalDeadline;

            lead.CriticalDeadline = cdt;

            try
            {
                _db.Entry(lead).State = EntityState.Modified;

                createViewModel.Address.AddressID        = lead.AddressID;
                _db.Entry(createViewModel.Address).State = EntityState.Modified;

                _db.SaveChanges();

                RecordLeadStatusChangdTime(lead);
                RecordLeadAeChangdTime(lead);
                LogMethods.Log.Debug("EditLead:Debug:" + "Done");
            }
            catch (Exception ex)
            {
                LogMethods.Log.Error("EditLead:Error:" + ex.Message);
            }
        }
Пример #3
0
        /// <summary>
        /// Delete an exising contact to corresponding lead
        /// </summary>
        /// <param name="contact"></param>
        /// <param name="username">user name, such as type whoami under command line \\F01\anh.tran</param>
        public void DeleteLeadContact(CrmLeadContact contact, string username)
        {
            var leadID = contact.LeadID;

            //Validation
            if (contact.CustomerContactID > 0)
            {
                LogMethods.Log.Error("DeleteLeadContact:Error:" + "The Lead has been convert to Customer, can not be deleted.");
                return;
            }
            var emp  = new CrmEmployee(username);
            var lead = _db.CrmLeads.Find(contact.LeadID);

            if (emp.UserEmployeeID != lead.OriginalOwner)
            {
                LogMethods.Log.Error("DeleteLeadContact:Error:" + "Only owner can delete contact.");
                return;
            }

            //to be deleted contact is Main Contact
            if (lead.ContactID == contact.ContactID)
            {
                lead.ContactID = 0;
                _db.Entry(lead).Property(x => x.ContactID).IsModified = true;
                _db.SaveChanges();
            }

            _db.Entry(contact).State = EntityState.Deleted;
            _db.SaveChanges();

            var contacts = _db.CrmLeadContacts.Where(x => x.LeadID == contact.LeadID);

            if (contacts.Count() > 0)
            {
                var firstContact = contacts.First();
                lead.ContactID        = firstContact.ContactID;
                _db.Entry(lead).State = EntityState.Modified;
                _db.SaveChanges();
            }
            LogMethods.Log.Debug("DeleteLeadContact:Debug:" + "Done");
        }