Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/21/16 16:48:34 (8 years ago)
Author:
jlodewyc
Message:

#2582 Resource calendar and client group creation, control implemented

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers/ResourceController.cs

    r13754 r13782  
    1 using HeuristicLab.Clients.Access.Administration;
     1using HeuristicLab.Clients.Access;
     2using HeuristicLab.Clients.Access.Administration;
    23using HeuristicLab.Clients.Hive.WebJobManager.Services;
    34using Microsoft.AspNet.Hosting;
     
    89using System.Linq;
    910using System.ServiceModel.Security;
     11using System.Threading;
    1012using System.Threading.Tasks;
    1113
     
    1719        private HiveServiceLocatorWeb serviceLocator;
    1820        private AccessAdministrationClient accessClient;
     21        private HiveAdminClientWeb adminClient;
    1922        private Guid userId;
    2023
     
    3740                userId = Guid.Parse(u);
    3841                serviceLocator = weblog.getServiceLocator(userId);
     42                adminClient = weblog.getAdminClient(userId);
    3943                accessClient = weblog.getAccessAdminClient(userId);
    4044                return serviceLocator.CheckLogin();
     
    5660            }
    5761        }
     62        [HttpPost]
     63        public IActionResult changeParent(string inpid, string inpidpar)
     64        {
     65            if (init())
     66            {
     67                var gid = Guid.Parse(inpid);
     68               
     69
     70                adminClient.Refresh();
     71                var tochange = adminClient.Resources.ToList().Find(x => x.Id == gid);
     72               
     73                if (inpidpar != null && inpidpar != "") {
     74                    Guid tempid = Guid.Parse(inpidpar);
     75                    while (tempid != null)
     76                    {
     77                        if (tempid != gid)
     78                        {
     79                            tempid = (Guid)adminClient.Resources.ToList().Find(x => x.Id == tempid).ParentResourceId;
     80                        }
     81                        else
     82                            break;
     83                    }
     84                    if(tempid == null)
     85                        tochange.ParentResourceId = Guid.Parse(inpidpar);
     86                }
     87                else
     88                    tochange.ParentResourceId = null;
     89                adminClient.Store(tochange, CancellationToken.None);
     90
     91                return RedirectToAction("Index", "Resource");
     92            }
     93            else
     94            {
     95                return RedirectToAction("Index", "Home");
     96            }
     97        }
     98        [HttpPost]
     99        public IActionResult deleteClientGroup(string inpid)
     100        {
     101            if (init())
     102            {
     103                var gid = Guid.Parse(inpid);
     104
     105                adminClient.Refresh();
     106                var group = adminClient.Resources.ToList().Find(x => x.Id == gid);
     107                var list = adminClient.Resources.ToList().FindAll(x => x.ParentResourceId == gid);
     108                foreach(var cl in list)
     109                {
     110                    cl.ParentResourceId = group.ParentResourceId;
     111                    adminClient.Store(cl, CancellationToken.None);
     112                }
     113                adminClient.Delete(group);
     114
     115                return RedirectToAction("Index", "Resource");
     116            }
     117            else
     118            {
     119                return RedirectToAction("Index", "Home");
     120            }
     121        }
     122
     123        [HttpPost]
     124        public IActionResult newClientGroup(string inpname, int inpheart, string inpparent, string[] clientstoadd)
     125        {
     126            if (init()) {
     127                adminClient.Refresh();
     128
     129                SlaveGroup sg = new SlaveGroup();
     130                sg.Id = Guid.Empty;
     131                sg.Name = inpname;
     132                sg.HbInterval = inpheart;
     133                if (inpparent != "")
     134                    sg.ParentResourceId = Guid.Parse(inpparent);
     135                sg.OwnerUserId = serviceLocator.getHiveServiceClient().GetUserIdByUsername(serviceLocator.getHiveServiceClient().ClientCredentials.UserName.UserName);
     136                adminClient.Store(sg, CancellationToken.None);
     137                adminClient.Refresh();
     138                var id = adminClient.Resources.ToList().Find(x => x.Name == inpname).Id;
     139                foreach(var s in clientstoadd)
     140                {
     141                    var cid = Guid.Parse(s);
     142                    var client = adminClient.Resources.ToList().Find(x => x.Id == cid);
     143                    client.ParentResourceId = id;
     144                    adminClient.Store(client, CancellationToken.None);
     145                }
     146
     147                return RedirectToAction("Index", "Resource");
     148            }
     149            else
     150            {
     151                return RedirectToAction("Index", "Home");
     152            }
     153        }
    58154    }
    59155}
Note: See TracChangeset for help on using the changeset viewer.