Exemple #1
0
        public ActionResult <ListDTO> CreateListForUser(ListToCreateDTO list)
        {
            try
            {
                var dblist = _mapper.Map <Data.DbModels.TList>(list);
                _listService.AddList(list.UserId, dblist);

                var listToReturn = _mapper.Map <ListDTO>(dblist);
                return(Ok(listToReturn));
            }
            catch (Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
Exemple #2
0
 public ActionResult Create(ListModel list)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (service.GetAllLists().All(e => e.Name != list.Name))
             {
                 service.AddList(list.ToServiceList());
                 if (Request.IsAjaxRequest())
                 {
                     var lim = Models.DataModels.List.GetListIndexModel();
                     return(PartialView("_ListCoverListView", lim));
                 }
                 return(RedirectToAction("Index"));
             }
         }
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         logger.Error(ex);
         return(View("Error"));
     }
 }
Exemple #3
0
        public async Task <IActionResult> AddList(string name)
        {
            var user = await _userManager.GetUserAsync(User);

            var model = new ListModel
            {
                Name    = name,
                OwnerId = user.Id
            };

            model = await _listService.AddList(model);

            return(Ok(model));
        }
Exemple #4
0
        public IActionResult AddList([FromBody] AddListDto addListDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var result = _listService.AddList(addListDto);

            if (result == null)
            {
                return(BadRequest());
            }

            return(Ok(result));
        }
        static void Main(string[] args)
        {
            Uri OrganizationUri = new Uri(String.Format("https://netunousa.api.crm.dynamics.com/XRMServices/2011/Organization.svc"));

            Uri HomeRealmUri = new Uri(String.Format("https://netunousa.api.crm.dynamics.com/XRMServices/2011/Discovery.svc"));

            Uri serviceUri = new Uri("https://netunousa.api.crm.dynamics.com/XRMServices/2011/Organization.svc");

            System.ServiceModel.Description.ClientCredentials clientCredentials = new System.ServiceModel.Description.ClientCredentials();

            clientCredentials.UserName.UserName = "******";
            clientCredentials.UserName.Password = "******";

            OrganizationServiceProxy serviceproxy = new OrganizationServiceProxy(OrganizationUri, null, clientCredentials, null);
            IOrganizationService     orgservice   = (IOrganizationService)serviceproxy;

            //ConditionExpression condition = new ConditionExpression();
            //condition.AttributeName = "new_sagecustomerid";
            //condition.Operator = ConditionOperator.Equal;
            //condition.Values.Add("0");
            string[]        cols       = { "listid", "listname", "new_constantcontactid" };
            ColumnSet       columns    = new ColumnSet(cols);
            QueryExpression expression = new QueryExpression();


            expression.EntityName = "list";
            //expression.ColumnSet = new AllColumns();
            expression.ColumnSet.AllColumns = true;

            QueryExpression query = new QueryExpression
            {
                EntityName = "list",
                ColumnSet  = new ColumnSet("listid", "listname", "new_constantcontactid"),
            };


            expression.ColumnSet = columns;


            EntityCollection       listEntityColl     = orgservice.RetrieveMultiple(query);
            IUserServiceContext    userServiceContext = new UserServiceContext("3f09fe65-10ae-44a9-9db6-d9f2d6de1dec", "cvwkqk7ajrm67rcagvfwn9gx");
            ConstantContactFactory serviceFactory     = new ConstantContactFactory(userServiceContext);
            IListService           listService        = serviceFactory.CreateListService();

            if (listEntityColl.Entities.Count > 0)
            {
                //get contact if exists (by email address)
                CTCT.Components.Contacts.ContactList list = null;


                for (int i = 0; i < listEntityColl.Entities.Count; i++)
                {
                    try
                    {
                        try
                        {
                            list = GetListByID(listEntityColl.Entities[i].Attributes["new_constantcontactid"].ToString(), ref listService);
                        }
                        catch (Exception ex)
                        {
                            CTCTLogger.LogFile(ex.InnerException.ToString(), ex.InnerException.ToString(), ex.Data.ToString(), (int)ex.LineNumber(), ex.Source.ToString());
                        }
                        bool alreadyExists = list != null ? true : false;
                        try
                        {
                            list = UpdateListFields(list, listEntityColl.Entities[i].Attributes);
                        }
                        catch (Exception ex)
                        {
                            CTCTLogger.LogFile(ex.InnerException.ToString(), ex.InnerException.ToString(), ex.Data.ToString(), (int)ex.LineNumber(), ex.Source.ToString());
                        }
                        // var contactService = _constantContactFactory.CreateContactService();
                        CTCT.Components.Contacts.ContactList result = null;
                        // IListService listService = serviceFactory.CreateListService();
                        if (alreadyExists)
                        {
                            try
                            {
                                result = listService.UpdateList(list);
                            }
                            catch (Exception ex)
                            {
                                CTCTLogger.LogFile(ex.InnerException.ToString(), ex.InnerException.ToString(), ex.Data.ToString(), (int)ex.LineNumber(), ex.Source.ToString());
                            }
                        }
                        else
                        {
                            try
                            {
                                // IBulkStatusService listService1 = serviceFactory.CreateBulkStatusService();


                                result = listService.AddList(list);
                                listEntityColl.Entities[i].Attributes["new_constantcontactid"] = result.Id;
                                orgservice.Update((Entity)listEntityColl.Entities[i]);
                            }

                            catch (Exception ex)
                            {
                                CTCTLogger.LogFile(ex.InnerException.ToString(), ex.InnerException.ToString(), ex.Data.ToString(), (int)ex.LineNumber(), ex.Source.ToString());
                                alreadyExists = true;
                            }
                        }

                        if (result != null)
                        {
                            if (alreadyExists)
                            {
                                //messageResult = "Changes successfully saved!";
                            }
                            else
                            {
                                //  messageResult = "Contact successfully added!";
                            }
                        }
                        else
                        {
                            if (alreadyExists)
                            {
                                //    messageResult = "Failed to save changes!";
                            }
                            else
                            {
                                //      messageResult = "Failed to add contact!";
                            }
                        }

                        //MessageBox.Show(messageResult, "Result");
                    }
                    catch (IllegalArgumentException illegalEx)
                    {
                        CTCTLogger.LogFile(illegalEx.InnerException.ToString(), illegalEx.InnerException.ToString(), illegalEx.Data.ToString(), (int)illegalEx.LineNumber(), illegalEx.Source.ToString());
                    }
                    catch (CtctException ctcEx)
                    {
                        CTCTLogger.LogFile(ctcEx.InnerException.ToString(), ctcEx.InnerException.ToString(), ctcEx.Data.ToString(), (int)ctcEx.LineNumber(), ctcEx.Source.ToString());
                    }
                    catch (OAuth2Exception oauthEx)
                    {
                        CTCTLogger.LogFile(oauthEx.InnerException.ToString(), oauthEx.InnerException.ToString(), oauthEx.Data.ToString(), (int)oauthEx.LineNumber(), oauthEx.Source.ToString());
                    }
                    catch (Exception ex)
                    {
                        CTCTLogger.LogFile(ex.InnerException.ToString(), ex.InnerException.ToString(), ex.Data.ToString(), (int)ex.LineNumber(), ex.Source.ToString());
                    }
                }

                //btnSave.Enabled = true;
            }


            if (listEntityColl.Entities.Count > 0)
            {
                bool flag = false;;

                for (int i = 0; i < listEntityColl.Entities.Count; i++)
                {
                    try
                    {
                        GetAllMembersInaList(listEntityColl.Entities[i].Attributes["listid"].ToString(), listEntityColl.Entities[i].Attributes["new_constantcontactid"].ToString(), flag, ref orgservice, ref listService);
                    }
                    catch (Exception ex)
                    {
                        CTCTLogger.LogFile(ex.InnerException.ToString(), ex.InnerException.ToString(), ex.Data.ToString(), (int)ex.LineNumber(), ex.Source.ToString());
                    }
                    flag = true;
                }
            }
        }
 public void AddList([FromBody] ApiList model)
 {
     _listService.AddList(Mapper.ToBllList(model));
 }