コード例 #1
0
        private PortalActionResult UpdateZohoIfNeeded(ZohoContact contact, Models.ZohoPartnerPortal partnerPortal, string oldPortalAdminContactId)
        {
            PortalActionResult result = new PortalActionResult();

            StringBuilder message = new StringBuilder();

            result.IsSuccess = false;

            var needUpdateContact       = true;
            var needUpdatePartnerPortal = true;
            var needUpdateOldContact    = false;
            //var needUpdateAccount = false;


            ZohoContact zohoOldAdminContact = null;

            if (!string.IsNullOrEmpty(oldPortalAdminContactId))
            {
                zohoOldAdminContact =
                    ZohoRepository.Contacts.FirstOrDefault(x => x.ContactID == oldPortalAdminContactId);
                if (zohoOldAdminContact.PortalAdmin)
                {
                    needUpdateOldContact = true;
                }
            }

            if (contact.PortalAdmin)
            {
                needUpdateContact = false;
                message.AppendLine("Portal Admin is true in Database, ignore update");
            }

            if (partnerPortal.ACLCreated.Equals("true", StringComparison.CurrentCultureIgnoreCase))
            {
                needUpdatePartnerPortal = false;
                message.AppendLine("Portal Portal ACL Created is true in Database, ignore update");
            }


            var account = ZohoRepository.Accounts.FirstOrDefault(x => x.AccountId == partnerPortal.PartnerAccount);

            if (account != null && account.PortalEnabled == false)
            {
                using (ZohoCRMProxy.ZohoCRMAccount accountRequest = new ZohoCRMProxy.ZohoCRMAccount(_zohoToken))
                {
                    try
                    {
                        var zAccount = new ZohoCRMProxy.ZohoAccount
                        {
                            Id            = partnerPortal.PartnerAccount,
                            PortalEnabled = true
                        };
                        accountRequest.Update(zAccount);
                        result.IsSuccess = true;
                        message.AppendLine("Zoho Account Updated.");
                    }
                    catch (Exception e)
                    {
                        result.IsSuccess = false;
                        message.AppendLine(e.Message);
                    }
                }
            }


            if (needUpdateContact || needUpdateOldContact)
            {
                var zohoContact = new ZohoCRMProxy.ZohoContact
                {
                    Id                   = contact.ContactID,
                    PortalAdmin          = true,
                    PartnerPortalEnabled = false,
                    SAPUnqualified       = contact.SAPUnqualified.Equals("true", StringComparison.CurrentCultureIgnoreCase),
                    EmailOptOut          = contact.EmailOptOut.Equals("true", StringComparison.CurrentCultureIgnoreCase),
                };

                using (ZohoCRMProxy.ZohoCRMContact request = new ZohoCRMContact(_zohoToken))
                {
                    try
                    {
                        if (needUpdateContact)
                        {
                            var contactResult = request.Update(zohoContact);

                            result.IsSuccess = true;
                            message.AppendLine("Zoho Contact Portal Admin Updated.");
                        }

                        if (needUpdateOldContact)
                        {
                            var oldAdminContactResult = request.Update(new ZohoCRMProxy.ZohoContact
                            {
                                Id                   = zohoOldAdminContact.ContactID,
                                PortalAdmin          = false,
                                PartnerPortalEnabled = true,
                                SAPUnqualified       =
                                    zohoOldAdminContact.SAPUnqualified.Equals("true",
                                                                              StringComparison.CurrentCultureIgnoreCase),
                                EmailOptOut =
                                    zohoOldAdminContact.EmailOptOut.Equals("true",
                                                                           StringComparison.CurrentCultureIgnoreCase),
                            });

                            result.IsSuccess = true;
                            message.AppendLine("Zoho Old Portal Admin Contact Updated.");
                        }
                    }
                    catch (Exception e)
                    {
                        result.IsSuccess = false;
                        message.AppendLine(e.Message);
                    }
                }
            }

            if (needUpdatePartnerPortal && result.IsSuccess)
            {
                var portal = new ZohoCRMProxy.ZohoPartnerPortal
                {
                    Id         = partnerPortal.PartnerPortalID,
                    ACLCreated = true
                };
                using (ZohoCRMProxy.ZohoCRMPartnerPortal portalRequest = new ZohoCRMProxy.ZohoCRMPartnerPortal(_zohoToken))
                {
                    try
                    {
                        portalRequest.Update(portal);
                        result.IsSuccess = true;
                        message.AppendLine("Zoho Partner Portal ACL Created Updated.");
                    }
                    catch (Exception e)
                    {
                        result.IsSuccess = false;
                        message.AppendLine(e.Message);
                    }
                }
            }



            result.Message = message.ToString();

            return(result);
        }
コード例 #2
0
        private async Task <PortalActionResult> CreateUserAndAddUserAsPortalAdminAsync(ZohoContact contact,
                                                                                       int companyId)
        {
            bool   isSuccess = false;
            string message;

            var now      = DateTime.Now;
            var tempuser = new ApplicationUser()
            {
                UserName = contact.Email, Email = contact.Email, LastPasswordChangedDate = now, CreationDate = now, CompanyId = companyId
            };
            var result = await _userManager.CreateAsync(tempuser, _tempPassword);

            if (result.Succeeded)
            {
                var roleResult = await _userManager.AddToRoleAsync(tempuser, DefaultRoleName);

                var userContact = await _userManager.CreateUserZohoContactAsync(new UserZohoContact
                {
                    UserId        = tempuser.Id,
                    ZohoContactId = contact.ContactID
                });

                if (roleResult.Succeeded)
                {
                    isSuccess = true;
                    message   = $"User Created for:{tempuser.UserName}";
                }
                else
                {
                    message = roleResult.ToString();
                }
            }
            else
            {
                message = result.ToString();
            }

            return(new PortalActionResult
            {
                IsSuccess = isSuccess,
                Message = message
            });
        }