Beispiel #1
0
        public IHttpActionResult DeleteUsers(List <DeleteUserModel> model)
        {
            if (model == null || model.Count == 0)
            {
                return(BadRequest("Lista nuk mund te jete bosh"));
            }

            List <OrganizationResponseModel> LISTMESSAGES = new List <OrganizationResponseModel>();

            foreach (var item in model)
            {
                var res = new OrganizationResponseModel {
                    UserKey = item.username, DisplayName = item.DisplayName
                };
                res.Messages.Add(DeleteUser(item));
                res.CalculateStatus();
                LISTMESSAGES.Add(res);
            }

            return(Ok(PrepareFinalResult(LISTMESSAGES)));
        }
Beispiel #2
0
        public List <OrganizationResponseModel> ChangeUserOrganization(List <UserToOrganizationModel> model)
        {
            List <OrganizationResponseModel> LISTMESSAGES = new List <OrganizationResponseModel>();

            var adduser    = httpservice.Post(new { usernames = model.Select(x => x.username).ToList() }, "servicedeskapi/organization/" + model.Select(x => x.OrganizationId).First().ToString() + "/user");
            var deleteuser = httpservice.Delete(new { usernames = model.Select(x => x.username).ToList() }, "servicedeskapi/organization/" + model.Select(x => x.CurrentOgranizationId).First() + "/user");



            if (adduser.status && deleteuser.status)
            {
                foreach (var user in model)
                {
                    var issueRes = new OrganizationResponseModel {
                        UserKey = user.username, DisplayName = user.DisplayName
                    };
                    issueRes.Messages.Add(new BaseResponseMessage {
                        status = true, message = "User(i)/at ndrysh(oi)/uan  me sukses ne organizate (if have lines below not all issues are assiged correctly into organization) !"
                    });
                    if (user.IssueUpdate)
                    {
                        var issues = GetIssuesOfUsers(user.username);

                        foreach (var item in issues.issues)
                        {
                            var req = new IssueOrganizationFiled();
                            req.fields.customfield_10004.Add(Convert.ToInt32(user.OrganizationId));
                            var response = httpservice.Put(req, "api/2/issue/" + item.key);
                            if (!response.status)
                            {
                                issueRes.Messages.Add(response);
                                //rollback
                                dataserviceinside.UpdateUserOrganization(new List <string>()
                                {
                                    user.username
                                }, user.CurrentOgranizationId);
                            }
                        }

                        issueRes.CalculateStatus();
                        LISTMESSAGES.Add(issueRes);
                        var commentdata = DataService.GetCompanyComments().Where(x => x.OrganizationId == user.OrganizationId.ToString()).FirstOrDefault();

                        if (commentdata != null)
                        {
                            var result = GetIssuesByJQL(commentdata.JQL);
                            AddComentsIntoIssues(result, commentdata.Comment, commentdata.customField_10075);
                        }
                    }
                }


                return(LISTMESSAGES);
            }
            else
            {
                foreach (var item in model)
                {
                    LISTMESSAGES.Add(new OrganizationResponseModel
                    {
                        UserKey  = item.username,
                        Messages = new List <Models.BaseResponseMessage> {
                            new Models.BaseResponseMessage {
                                message = adduser.message + ":" + deleteuser.message
                            }
                        }
                    });
                }
                return(LISTMESSAGES);
            }
        }