Ejemplo n.º 1
0
        protected override async Task <PortalActionResult> ProcessImport(string id)
        {
            var bitdefender = ZohoRepository.Bitdefenders.FirstOrDefault(x => x.BitdefenderID.Equals(id, StringComparison.CurrentCultureIgnoreCase));

            if (bitdefender == null)
            {
                return(new PortalActionResult
                {
                    IsSuccess = false,
                    Message = string.Format("Could not find Bitdefender record for id:{0}", id)
                });
            }

            var accountId = bitdefender.BDPartner;

            var company = await _userManager.GetCompanyByZohoAccountIdAsync(accountId);

            if (company == null)
            {
                return(new PortalActionResult
                {
                    IsSuccess = false,
                    Message = string.Format("Could not find Account/Company information for Zoho Account id:{0}", accountId)
                });
            }

            var companyHasClaim = await _userManager.ComanyHasClaimAsync(company.Id, _bdClarimType, _bdClarimValue);

            if (companyHasClaim)
            {
                return(new PortalActionResult
                {
                    IsSuccess = true,
                    Message = string.Format("Account {0} already has Bitdefender module permission", accountId)
                });
            }


            var result = _userManager.CreateCompanyClaimAsync(new CompanyClaims
            {
                CompanyId  = company.Id,
                ClaimType  = _bdClarimType,
                ClaimValue = _bdClarimValue
            });


            return(new PortalActionResult
            {
                IsSuccess = true,
                Message = string.Format("Bitdefender Permission added for Account:{0}", accountId)
            });
        }
        protected override async Task <PortalActionResult> ProcessImport(string id = "")
        {
            string validateResult = await ValidatePartnerPortalAsync(id);

            if (!string.IsNullOrEmpty(validateResult))
            {
                return(new PortalActionResult
                {
                    IsSuccess = false,
                    Message = validateResult
                });
            }

            var partnerPortal =
                ZohoRepository.PartnerPortals.FirstOrDefault(x => x.PartnerPortalID.Equals(id));

            var accountId = partnerPortal.PartnerAccount;

            var contactId = partnerPortal.PortalAdmin;

            //PortalActionResult myobResult = await MyobContactCustomerDataSyncAysnc(accountId, id);
            //if (!myobResult.IsSuccess)
            //{
            //    return myobResult;
            //}


            //var subject = myobResult.IsSuccess
            //    ? $"[Account:{accountId}] added to Myob"
            //    : $"[Account:{accountId}] could not add to Myob";

            //var tos = _myobApiService.SalesEmail.Split(new char[] { ';' }).ToList();
            //var body = string.IsNullOrEmpty(myobResult.Message) ? "Success" : myobResult.Message;

            ////do not need wait for email result
            //EmailSender.SendEmailAsync(subject, body, tos);


            //check contact created in company
            var company = await _userManager.GetCompanyByZohoAccountIdAsync(accountId);

            int companyId;

            if (company == null)
            {
                companyId = await _userManager.CreateCompanyAsync(new Company
                {
                    CompanyZohoAccountId = accountId,
                    CreatedBy            = "importer",
                    CreatedTime          = DateTime.Now
                });
            }
            else
            {
                companyId = company.Id;
            }

            string oldPortalAdminZohoContactId = await UpdateOldPortalAdminIfNeededAsync(companyId, contactId);

            //check user information
            var contact = ZohoRepository.Contacts.FirstOrDefault(x => x.ContactID == contactId);

            var user = await _userManager.FindByEmailAsync(contact.Email);

            var message   = string.Empty;
            var isSuccess = false;

            if (user == null)
            {
                PortalActionResult updateResult
                    = await CreateUserAndAddUserAsPortalAdminAsync(contact, companyId);

                isSuccess = updateResult.IsSuccess;
                message   = updateResult.Message;

                //create user
            }
            else
            {
                var updateResult
                    = await UpdateExistingUserAsPortalAdminAsync(user, companyId);

                isSuccess = updateResult.IsSuccess;
                message   = updateResult.Message;
            }

            if (isSuccess)
            {
                var updateResult = UpdateZohoIfNeeded(contact, partnerPortal, oldPortalAdminZohoContactId);
                return(new PortalActionResult
                {
                    IsSuccess = updateResult.IsSuccess,
                    Message = string.Format("{0}\r\n{1}", message, updateResult.Message)
                });
            }
            else
            {
                return(new PortalActionResult
                {
                    IsSuccess = false,
                    Message = message
                });
            }
        }