Esempio n. 1
0
        //[HttpGet]
        //public ActionResult Get(int id)
        //{
        //    var apiResult = TryExecute(() => _crmAccountRepository.Get(id, "AssignedToEmployee.User.Person,Parent"), "CRM Account fetched sucessfully");
        //    var json = JsonConvert.SerializeObject(apiResult, Formatting.None, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
        //    return Content(json, "application/json");
        //}
        //[HttpGet]
        //public ActionResult Get(int id)
        //{
        //    var apiResult = TryExecute(() => _crmAccountRepository.Get(id, "AssignedToEmployee.User.Person,Parent"), "CRM Account Fetched sucessfully");
        //    return Json(apiResult, JsonRequestBehavior.AllowGet);
        //}

        //[HttpGet]

        public JsonResult Get(int id)
        {
            var apiResult = TryExecute(() =>
            {
                var account   = _crmAccountRepository.Get(id, "AssignedToEmployee.User.Person,Parent");
                var accountVm = new CRMAccountModel(account);
                return(accountVm);
            }, "CRM Account Fetched sucessfully");

            return(Json(apiResult, JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        public ActionResult Update(CRMAccountModel cRMAccount)
        {
            ApiResult <CRMAccount> apiResult;

            if (ModelState.IsValid)
            {
                if (cRMAccount.Id > 0)
                {
                    apiResult = TryExecute(() =>
                    {
                        var selectedAccount = _crmAccountRepository.Get(cRMAccount.Id);

                        if (selectedAccount != null)
                        {
                            selectedAccount.Title                = cRMAccount.Title;
                            selectedAccount.Industry             = cRMAccount.Industry;
                            selectedAccount.EmployeeCount        = cRMAccount.EmployeeCount;
                            selectedAccount.FoundedOn            = cRMAccount.FoundedOn;
                            selectedAccount.Email                = cRMAccount.Email;
                            selectedAccount.PhoneNo              = cRMAccount.PhoneNo;
                            selectedAccount.SecondaryEmail       = cRMAccount.SecondaryEmail;
                            selectedAccount.OfficePhone          = cRMAccount.OfficePhone;
                            selectedAccount.Website              = cRMAccount.Website;
                            selectedAccount.Facebook             = cRMAccount.Facebook;
                            selectedAccount.Twitter              = cRMAccount.Twitter;
                            selectedAccount.GooglePlus           = cRMAccount.GooglePlus;
                            selectedAccount.LinkedIn             = cRMAccount.LinkedIn;
                            selectedAccount.City                 = cRMAccount.City;
                            selectedAccount.Country              = cRMAccount.Country;
                            selectedAccount.Address              = cRMAccount.Address;
                            selectedAccount.CommunicationAddress = cRMAccount.CommunicationAddress;
                            selectedAccount.Expertise            = cRMAccount.Expertise;
                            selectedAccount.Description          = cRMAccount.Description;
                            selectedAccount.AssignedToEmployeeId = cRMAccount.AssignedToEmployeeId;
                            selectedAccount.ParentId             = cRMAccount.ParentId;
                            selectedAccount.UpdatedByUserId      = WebUser.Id;

                            _crmAccountRepository.Update(selectedAccount);
                            _unitOfWork.Commit();
                        }

                        return(selectedAccount);
                    }, "CRM Account updated sucessfully");
                }

                else
                {
                    apiResult = TryExecute(() =>
                    {
                        var crmAccount = new CRMAccount
                        {
                            Title                = cRMAccount.Title,
                            Industry             = cRMAccount.Industry,
                            EmployeeCount        = cRMAccount.EmployeeCount,
                            FoundedOn            = cRMAccount.FoundedOn,
                            Email                = cRMAccount.Email,
                            PhoneNo              = cRMAccount.PhoneNo,
                            SecondaryEmail       = cRMAccount.SecondaryEmail,
                            OfficePhone          = cRMAccount.OfficePhone,
                            Website              = cRMAccount.Website,
                            Facebook             = cRMAccount.Facebook,
                            Twitter              = cRMAccount.Twitter,
                            GooglePlus           = cRMAccount.GooglePlus,
                            LinkedIn             = cRMAccount.LinkedIn,
                            City                 = cRMAccount.City,
                            Country              = cRMAccount.Country,
                            Address              = cRMAccount.Address,
                            CommunicationAddress = cRMAccount.CommunicationAddress,
                            Expertise            = cRMAccount.Expertise,
                            Description          = cRMAccount.Description,
                            AssignedToEmployeeId = cRMAccount.AssignedToEmployeeId,
                            ParentId             = cRMAccount.ParentId,
                            CreatedByUserId      = WebUser.Id,
                        };
                        _crmAccountRepository.Create(crmAccount);
                        _unitOfWork.Commit();
                        return(crmAccount);
                    }, "CRM Account created sucessfully");
                }
            }
            else
            {
                apiResult = ApiResultFromModelErrors <CRMAccount>();
            }

            return(Json(apiResult, JsonRequestBehavior.AllowGet));
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the Accounts associated with a Team and/or DSM2
        /// </summary>
        /// <param name="TeamID">Team or DSM2 ID</param>
        /// <param name="DSM2">Not Used</param>
        /// <returns>List of Account Model class</returns>
        public static List <CRMAccountModel> GetCRMAccountsForTeamService(string TeamID, string DSM2)
        {
            List <CRMAccountModel> theAccounts = new List <CRMAccountModel>();

            try
            {
                CrmServiceClient conn = new CrmServiceClient(DatabaseServices.GetCRMDBConnectionString());

                IOrganizationService _orgService;
                _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;

                Guid objGuid = Guid.Empty;
                if (Guid.TryParse(TeamID, out objGuid))
                {
                    // string can be converted to GUID
                    // no additional processing needed
                }
                else
                {
                    // can not parse into a guid
                    throw new Exception("Can not convert TeamID into GUID");
                }

                QueryExpression query = new QueryExpression
                {
                    EntityName = "account",
                    ColumnSet  = new ColumnSet("accountid", "name", "csi_facilityname", "ownerid", "new_dsm2"),
                    Criteria   =
                    {
                        Filters                =
                        {
                            new FilterExpression
                            {
                                FilterOperator = LogicalOperator.Or,
                                Conditions     =
                                {
                                    //new ConditionExpression("ownerid", ConditionOperator.Equal, TeamID.Trim()),
                                    new ConditionExpression("ownerid",  ConditionOperator.Equal, objGuid),
                                    //new ConditionExpression("new_dsm2", ConditionOperator.Equal, TeamID.Trim())
                                    new ConditionExpression("new_dsm2", ConditionOperator.Equal, objGuid)
                                }
                            }
                        }
                    }
                };
                // return records sorted by name
                //query.AddOrder("csi_facilityname", OrderType.Ascending);
                query.AddOrder("name", OrderType.Ascending);

                EntityCollection entityRecords = _orgService.RetrieveMultiple(query);

                // see if data returned
                if (entityRecords != null && entityRecords.Entities.Count > 0)
                {
                    CRMAccountModel entityModel;
                    for (int i = 0; i < entityRecords.Entities.Count; i++)
                    {
                        // new blank copy of the C# model
                        entityModel = new CRMAccountModel();

                        if (entityRecords[i].Contains("accountid") && entityRecords[i]["accountid"] != null)
                        {
                            entityModel.Id = entityRecords[i]["accountid"].ToString();
                        }
                        if (entityRecords[i].Contains("csi_facilityname") && entityRecords[i]["csi_facilityname"] != null)
                        {
                            entityModel.CSI_FacilityName = entityRecords[i]["csi_facilityname"].ToString();
                        }
                        if (entityRecords[i].Contains("name") && entityRecords[i]["name"] != null)
                        {
                            entityModel.Name = CRMUtilityServices.GetTitleCaseService(entityRecords[i]["name"].ToString());
                        }
                        if (entityRecords[i].Contains("ownerid") && entityRecords[i]["ownerid"] != null)
                        {
                            EntityReference ownerRef = entityRecords[i].GetAttributeValue <EntityReference>("ownerid");
                            entityModel.OwnerID = ownerRef.Id.ToString();
                            //entityModel.OwnerID = entityRecords[i]["ownerid"].ToString();
                        }
                        if (entityRecords[i].Contains("new_dsm2") && entityRecords[i]["new_dsm2"] != null)
                        {
                            EntityReference ownerRef = entityRecords[i].GetAttributeValue <EntityReference>("new_dsm2");
                            entityModel.OwnerID = ownerRef.Id.ToString();
                            //entityModel.New_DSM2 = entityRecords[i]["new_dsm2"].ToString();
                        }

                        // add row to collection
                        theAccounts.Add(entityModel);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(theAccounts);
        }
Esempio n. 4
0
        public static List <CRMAccountModel> CRMGetSharedAccountsService(string userID)
        {
            List <CRMAccountModel> theAccts = new List <CRMAccountModel>();

            try
            {
                CrmServiceClient conn = new CrmServiceClient(DatabaseServices.GetCRMDBConnectionString());

                IOrganizationService _orgService;
                _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;

                Guid objGuid = Guid.Empty;
                if (Guid.TryParse(userID, out objGuid))
                {
                    // string can be converted to GUID
                    // no additional processing needed
                }
                else
                {
                    // can not parse into a guid
                    throw new Exception("Can not convert User ID into GUID");
                }

                QueryExpression query = new QueryExpression
                {
                    EntityName = "principalobjectaccess",
                    ColumnSet  = new ColumnSet("objectid"),

                    LinkEntities =
                    {
                        new LinkEntity
                        {
                            Columns               = new ColumnSet("accountid", "name"),
                            EntityAlias           = "acct",
                            JoinOperator          = JoinOperator.LeftOuter,
                            LinkFromAttributeName = "objectid",
                            LinkFromEntityName    = "principalobjectaccess",
                            LinkToAttributeName   = "accountid",
                            LinkToEntityName      = "account"
                        }
                    },

                    Criteria =
                    {
                        Filters                =
                        {
                            new FilterExpression
                            {
                                FilterOperator = LogicalOperator.And,
                                Conditions     =
                                {
                                    new ConditionExpression("objecttypecode",    ConditionOperator.Equal, "account"),
                                    new ConditionExpression("principaltypecode", ConditionOperator.Equal, "systemuser"),
                                    new ConditionExpression("principalid",       ConditionOperator.Equal, objGuid)
                                }
                            }
                        }
                    }
                };
                // return records sorted by name
                //query.AddOrder("csi_facilityname", OrderType.Ascending);
                //query.AddOrder("name", OrderType.Ascending);

                EntityCollection entityRecords = _orgService.RetrieveMultiple(query);

                // see if data returned
                if (entityRecords != null && entityRecords.Entities.Count > 0)
                {
                    CRMAccountModel entityModel;
                    for (int i = 0; i < entityRecords.Entities.Count; i++)
                    {
                        // new blank copy of the C# model
                        entityModel = new CRMAccountModel();

                        if (entityRecords[i].Contains("acct.accountid") && entityRecords[i]["acct.accountid"] != null)
                        {
                            AliasedValue acctID = entityRecords[i].GetAttributeValue <AliasedValue>("acct.accountid");
                            entityModel.Id = acctID.Value.ToString();
                        }
                        if (entityRecords[i].Contains("acct.name") && entityRecords[i]["acct.name"] != null)
                        {
                            AliasedValue acctN = entityRecords[i].GetAttributeValue <AliasedValue>("acct.name");
                            entityModel.Name             = CRMUtilityServices.GetTitleCaseService(acctN.Value.ToString());
                            entityModel.CSI_FacilityName = entityModel.Name;
                        }
                        // add row to collection
                        theAccts.Add(entityModel);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(theAccts);
        }