Exemple #1
0
        public ActionResult Create(GetContactInfoByContactID_Result Model)
        {
            var errorList = new List <string>();

            if (ModelState.IsValid)
            {
                int contactID = SaveContact(Model);
                Model.ViewID = contactID;
                if (contactID > 0)
                {
                    Int64 id = SyncObjectsModelId;
                    //QBAuthorizationdto oAuthDetails = new QBOAuthService(new QBAuthorizationdto()).GetAccessToken(this);
                    //if (oAuthDetails != null)
                    //{
                    //    syncService = new QBSyncService(oAuthDetails);
                    //    syncObjects = id > 0 ? GetSyncObjects(this, id) : new QBSyncdto();
                    //    syncObjects.OauthToken = oAuthDetails;
                    //    syncObjects.CompanyId = oAuthDetails.Realmid;
                    //    if (Model.TypeID == 1)
                    //    {
                    //        if (!syncService.IsCustSync(syncObjects, syncService, siteusercompanyid).IsCustomerSync)
                    //        {
                    //            syncObjects = syncService.GetDatafromModelCustomer(syncObjects, siteusercompanyid);
                    //            if (syncObjects.CustomerList.Count > 0)
                    //            {
                    //                syncObjects = syncService.SyncCustomer(this, syncObjects);
                    //            }
                    //            this.Save(this, syncObjects);
                    //        }
                    //    }
                    //    else if (Model.TypeID == 3)
                    //    {
                    //        if (!syncService.IsVendorSync(syncObjects, syncService, siteusercompanyid).IsVendorSync)
                    //        {
                    //            syncObjects = syncService.GetDatafromModelVendor(syncObjects, siteusercompanyid);
                    //            if (syncObjects.VendorList.Count > 0)
                    //            {
                    //                syncObjects = syncService.SyncVendor(this, syncObjects);
                    //            }
                    //            this.Save(this, syncObjects);
                    //        }
                    //    }
                    //}
                    return(Json(new { status = "success", contactID }));
                }
                else
                {
                    errorList.Add("Contact couldn't be saved. Please retry.");
                }
            }
            errorList.AddRange((from item in ModelState.Values
                                from error in item.Errors
                                select error.ErrorMessage).ToList()
                               );
            return(Json(new { status = "error", errors = errorList }));
        }
Exemple #2
0
        private bool EditContact(GetContactInfoByContactID_Result Model)
        {
            int siteCoID = siteusercompanyid;

            CommonRepository   repo    = new CommonRepository();
            CoContactCompanies company = null;

            if (!string.IsNullOrWhiteSpace(Model.ContactCompany))
            {
                company = repo.AddCompany(siteCoID, Model.ContactCompany);
            }
            if (company == null)
            {
                company = new CoContactCompanies()
                {
                    ContactCoID = 0
                };
            }

            CoContacts contact = db.CoContacts
                                 .Include(p => p.CoContactAddresses)
                                 .Include(p => p.CoContactEmails)
                                 .Where(p => p.ContactID == Model.ViewID).FirstOrDefault();

            contact.ContactID        = Model.ViewID;
            contact.SiteCoID         = siteCoID;
            contact.ContactTypeID    = Model.ContactTypeID ?? 0;
            contact.ContactSubtypeID = Model.ContactSubtypeID ?? 0;
            contact.ContactStatusID  = Model.ContactStatusID;
            contact.ContactFirstName = Model.ContactFirst;
            contact.ContactLastName  = Model.ContactLast;
            contact.ContactCoID      = company.ContactCoID;
            contact.ModifiedDate     = DateTime.Now;
            contact.ContactManager   = Model.ContactOwnerID;
            contact.Custom1          = Model.Custom1;
            contact.Custom2          = Model.Custom2;
            contact.Custom3          = Model.Custom3;
            contact.Custom4          = Model.Custom4;
            db.SaveChanges();

            repo.UpdatePhone(Model.ViewID, (int)EnumWrapper.PhoneTypes.Mobile, Model.Mobile, true);
            repo.UpdatePhone(Model.ViewID, (int)EnumWrapper.PhoneTypes.Phone, Model.Phone, true);
            repo.UpdateEmail(Model.ViewID, Model.ContactEmail, true);
            repo.UpdateAddress(Model.ViewID, new CoContactAddresses()
            {
                Address1      = Model.ContactAddress1,
                Address2      = Model.ContactAddress2,
                City          = Model.ContactCity,
                State         = Model.ContactState,
                Zip           = Model.ContactZip,
                CountryID     = Model.CountryID,
                AddressTypeID = (int)EnumWrapper.AddressTypes.Main
            });
            return(true);
        }
Exemple #3
0
        public ActionResult Edit(int id)
        {
            var siteCoID = siteusercompanyid;

            ViewBag.ContactCo      = new SelectList(db.GetContactCompaniesBySiteCoID(siteCoID), "ViewID", "Company", siteCoID);
            ViewBag.Country        = new SelectList(new CommonRepository().GetCountries(), "CountryID", "Country");
            ViewBag.ContactType    = new SelectList(db.GetPeopleTypesBySiteCoID(siteCoID), "ViewID", "Name", siteCoID);
            ViewBag.ContactSubType = new SelectList(db.GetContactSubTypesBySiteCoID(siteCoID), "ViewID", "Type", siteCoID);
            ViewBag.ContactStatus  = new SelectList(db.SiteContactStatus.OrderBy(p => p.StatusOrder), "StatusID", "Status");
            ViewBag.Owner          = new SelectList(db.GetCoUsersBySiteCoID(siteCoID), "UserID", "User", siteCoID);
            ViewBag.ContactCustoms = db.GetContactCustomFieldsBySiteCoID(siteCoID).FirstOrDefault();
            ViewBag.siteuserid     = siteuserid;

            GetContactInfoByContactID_Result Model = new GetContactInfoByContactID_Result();
            CoContacts contact = db.CoContacts
                                 .Include(p => p.CoContactAddresses)
                                 .Include(p => p.CoContactEmails)
                                 .Where(p => p.ContactID == id).FirstOrDefault();
            CoContactAddresses address = contact.CoContactAddresses.Where(p => p.ContactID == id).FirstOrDefault() ?? new CoContactAddresses();

            if (contact != null)
            {
                Model = new GetContactInfoByContactID_Result()
                {
                    ContactAddress1  = address.Address1,
                    ContactAddress2  = address.Address2,
                    ContactCity      = address.City,
                    CountryID        = address.CountryID,
                    ContactState     = address.State,
                    ContactZip       = address.Zip,
                    ContactCompany   = contact.CoContactCompanies != null ? contact.CoContactCompanies.ContactCoName : "",
                    ViewID           = contact.ContactID,
                    ContactEmail     = contact.CoContactEmails.Any() ? contact.CoContactEmails.Select(p => p.EmailAddress).FirstOrDefault() : "",
                    ContactFirst     = contact.ContactFirstName,
                    ContactLast      = contact.ContactLastName,
                    Mobile           = contact.CoContactPhones.Any() ? contact.CoContactPhones.Where(p => p.PhoneTypeID == 2).Select(p => p.Phone).FirstOrDefault() : "",
                    Phone            = contact.CoContactPhones.Any() ? contact.CoContactPhones.Where(p => p.PhoneTypeID == 1).Select(p => p.Phone).FirstOrDefault() : "",
                    ContactStatusID  = contact.ContactStatusID,
                    ContactTypeID    = contact.ContactTypeID,
                    ContactOwnerID   = contact.ContactManager,
                    ContactSubtypeID = contact.ContactSubtypeID,
                    FaceBook         = contact.FaceBook,
                    LinkedIn         = contact.LinkedIn,
                    Skype            = contact.Skype,
                    Custom1          = contact.Custom1,
                    Custom2          = contact.Custom2,
                    Custom3          = contact.Custom3,
                    Custom4          = contact.Custom4
                };
            }

            return(View("_Edit", Model));
        }
Exemple #4
0
        public ActionResult Edit(GetContactInfoByContactID_Result Model)
        {
            var errorList = new List <string>();

            if (ModelState.IsValid)
            {
                if (EditContact(Model))
                {
                    return(Json(new { status = "success", contactID = Model.ViewID }));
                }
                else
                {
                    errorList.Add("Contact couldn't be updated. Please retry.");
                }
            }

            errorList.AddRange((from item in ModelState.Values
                                from error in item.Errors
                                select error.ErrorMessage).ToList()
                               );

            return(Json(new { status = "error", errors = errorList }));
        }
Exemple #5
0
        // GET: Pages/ContactInfo/Create
        public ActionResult Create(int?contactid, int?contactTypeID)
        {
            var siteCoID = siteusercompanyid;

            ViewBag.ContactCo      = new SelectList(db.GetContactCompaniesBySiteCoID(siteCoID), "ViewID", "Company", siteCoID);
            ViewBag.Country        = new SelectList(new CommonRepository().GetCountries(), "CountryID", "Country");
            ViewBag.ContactType    = new SelectList(db.GetPeopleTypesBySiteCoID(siteCoID), "ViewID", "Name", siteCoID);
            ViewBag.ContactSubType = new SelectList(db.GetContactSubTypesBySiteCoID(siteCoID), "ViewID", "Type", siteCoID);
            ViewBag.ContactStatus  = new SelectList(db.SiteContactStatus.OrderBy(p => p.StatusOrder), "StatusID", "Status");
            ViewBag.Owner          = new SelectList(db.GetCoUsersBySiteCoID(siteCoID), "UserID", "User", siteCoID);
            ViewBag.ContactCustoms = db.GetContactCustomFieldsBySiteCoID(siteCoID).FirstOrDefault();
            ViewBag.siteuserid     = siteuserid;
            qbModels = new QBModels();
            qbModels.SyncObjectsModel    = new QBSyncdto();
            qbModels.OAuthorizationModel = new QBAuthorizationdto();
            qbModels.IsReadySync         = false;
            var oAuthModel = new QBOAuthService(qbModels.OAuthorizationModel).IsTokenAvailable(this, siteusercompanyid);

            ViewBag.IsQBConnected = "false";
            if (oAuthModel.IsConnected)
            {
                qbModels.IsReadySync         = true;
                qbModels.OAuthorizationModel = oAuthModel;
                qbModels.IsConnected         = oAuthModel.IsConnected;
                var syncService = new QBSyncService(oAuthModel);
                qbModels.SyncObjectsModel.OauthToken = oAuthModel;
                Random random = new Random();
                SyncObjectsModelId    = random.Next(1, 100);
                ViewBag.IsQBConnected = "true";
                //SyncObjectsModelId = qbModels.SyncObjectsModel.Id;
            }
            GetContactInfoByContactID_Result Model = new GetContactInfoByContactID_Result();

            Model.ViewID = 0;
            return(View(Model));
        }
Exemple #6
0
        private int SaveContact(GetContactInfoByContactID_Result Model)
        {
            int siteCoID = siteusercompanyid;

            CommonRepository   repo    = new CommonRepository();
            CoContactCompanies company = null;

            if (!string.IsNullOrWhiteSpace(Model.ContactCompany))
            {
                company = repo.AddCompany(siteCoID, Model.ContactCompany);
            }
            if (company == null)
            {
                company = new CoContactCompanies()
                {
                    ContactCoID = 0
                };
            }

            var coContact = new CoContacts()
            {
                ContactID        = Model.ViewID,
                SiteCoID         = siteCoID,
                ContactTypeID    = Model.ContactTypeID ?? 0,
                ContactSubtypeID = Model.ContactSubtypeID ?? 0,
                //When creating it needs to be set to 1 Active otherwise if they do Not it errors - REQUIRED
                ContactStatusID  = Model.ContactStatusID,
                ContactFirstName = Model.ContactFirst,
                ContactLastName  = Model.ContactLast,
                ContactCoID      = company.ContactCoID,
                ModifiedDate     = DateTime.Now,
                Custom1          = Model.Custom1,
                Custom2          = Model.Custom2,
                Custom3          = Model.Custom3,
                Custom4          = Model.Custom4,
                ContactManager   = Model.ContactOwnerID
            };

            coContact.CoContactPhones.Add(new CoContactPhones()
            {
                PhoneTypeID = (int)EnumWrapper.PhoneTypes.Mobile, Phone = Model.Mobile, IsDefault = true
            });
            coContact.CoContactPhones.Add(new CoContactPhones()
            {
                PhoneTypeID = (int)EnumWrapper.PhoneTypes.Phone, Phone = Model.Phone, IsDefault = true
            });
            coContact.CoContactEmails.Add(new CoContactEmails()
            {
                EmailAddress = Model.ContactEmail, IsDefault = true
            });
            coContact.CoContactAddresses.Add(new CoContactAddresses()
            {
                Address1      = Model.ContactAddress1,
                Address2      = Model.ContactAddress2,
                City          = Model.ContactCity,
                State         = Model.ContactState,
                Zip           = Model.ContactZip,
                CountryID     = Model.CountryID,
                AddressTypeID = (int)EnumWrapper.AddressTypes.Main
            });

            int contactID = repo.AddContact(coContact);

            if (contactID > 0)
            {
                return(contactID);
            }
            else
            {
                return(0);
            }
        }