コード例 #1
0
        public async Task <IActionResult> UpdateService(int id, ServiceView serviceView)
        {
            var service = await _context.Services.FindAsync(id);

            if (service == null)
            {
                return(NotFound());
            }

            service.ServiceId   = serviceView.ServiceId;
            service.ServiceName = serviceView.ServiceName;
            service.StartTime   = serviceView.StartTime;
            service.EndTime     = serviceView.EndTime;
            service.IsAvailable = serviceView.IsAvailable;


            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(NotFound());
            }

            return(Ok());
        }
コード例 #2
0
        public ActionResult UpdateService(ServiceView sv)
        {
            var res = GlobalVariables.client.PutAsJsonAsync("Service/" + sv.IDService.ToString(), sv).Result;

            TempData["success"] = "Update service successfully!";
            return(RedirectToAction("ServiceList"));
        }
コード例 #3
0
        public ActionResult CreateService(ServiceView sv)
        {
            var res = GlobalVariables.client.PostAsJsonAsync("Service", sv).Result;

            TempData["success"] = "Create new service successfully!";
            return(RedirectToAction("ServiceList"));
        }
コード例 #4
0
            public void DoAction()
            {
                ServiceView serviceView = new ServiceView();

                serviceView.DataContext = new ServiceViewModel(_viewModel._unitOfWork);
                serviceView.ShowDialog();
            }
コード例 #5
0
        public ActionResult Index(ServiceView serviceView, string CaseId)
        {
            if (ModelState.IsValid)
            {
                Service service = new Service();

                service.Name       = serviceView.Name;
                service.AreaCodeAM = serviceView.AreaCodeAM;
                service.TelphoneAM = serviceView.TelphoneAM;
                service.AreaCodePM = serviceView.AreaCodePM;
                service.TelphonePM = serviceView.TelphonePM;
                service.Mobile     = serviceView.Mobile;
                service.Email      = serviceView.Email;
                if (serviceView.User == "是")
                {
                    serviceView.User = CaseId;
                }
                service.User      = "******";
                service.ShortMemo = serviceView.ShortMemo;

                db.Services.Add(service);
                service.Create(db, db.Services);
                ViewBag.state  = "success";
                ViewBag.CaseId = new SelectList(db.Cases.OrderBy(p => p.InitDate), "Subject", "Subject");
                return(View(serviceView));
            }
            ViewBag.CaseId = new SelectList(db.Cases.OrderBy(p => p.InitDate), "Subject", "Subject");
            return(View(serviceView));
        }
コード例 #6
0
        public void AddService(ServiceView service)
        {
            Services services = mapper.Map <ServiceView, Services>(service);

            db.Services.Add(services);
            db.SaveChanges();
        }
コード例 #7
0
 //客服点击
 public void OnServiceClick()
 {
     Global.Inst.GetController <ServiceController>().GetServiceInfo((info) =>
     {
         ServiceView v = Global.Inst.GetController <ServiceController>().OpenWindow() as ServiceView;
         v.SetData(info);
     });
 }
コード例 #8
0
        public async Task <IActionResult> UpdateService(Guid id, [FromBody] UpdateServiceCommand command)
        {
            ServiceView s = await mediator.Dispatch <UpdateServiceCommand, ServiceView>(
                command,
                User.GetUserId()
                );

            return(Ok(s));
        }
コード例 #9
0
        public async Task <IActionResult> CreateService(CreateServiceCommand command)
        {
            ServiceView s = await mediator.Dispatch <CreateServiceCommand, ServiceView>(
                command,
                User.GetUserId()
                );

            return(Ok(s));
        }
コード例 #10
0
 public ActionResult Edit([Bind(Include = "Id,ServiceName,Price,Duration,Status")] ServiceView serviceView)
 {
     if (ModelState.IsValid)
     {
         _serviceManager.UpdateService(serviceView);
         return(RedirectToAction("Index"));
     }
     return(View(serviceView));
 }
コード例 #11
0
        public IHttpActionResult Get(int id)
        {
            var item    = Repositories.GetServiceByID(id);
            var service = new ServiceView {
                IDService = item.IDService, IDCateSer = item.IDCateSer, NameCateSer = item.CategoryService.NameCateSer, NameService = item.NameService, PriceService = item.PriceService
            };

            return(Ok(service));
        }
コード例 #12
0
        // PUT api/<controller>/5
        public IHttpActionResult Put(int id, ServiceView sv)
        {
            var item = new Service {
                IDService = sv.IDService, IDCateSer = sv.IDCateSer, NameService = sv.NameService, PriceService = sv.PriceService
            };

            Repositories.UpdateService(item);
            return(Ok());
        }
コード例 #13
0
        // POST api/<controller>
        public IHttpActionResult Post(ServiceView sv)
        {
            var newItem = new Service {
                NameService = sv.NameService, IDCateSer = sv.IDCateSer, PriceService = sv.PriceService
            };

            Repositories.CreateService(newItem);
            return(Ok());
        }
コード例 #14
0
 public static void Start()
 {
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     mainForm    = new MainForm();
     carView     = new CarView();
     partView    = new PartView();
     serviceView = new ServiceView();
     Application.Run(mainForm);
 }
コード例 #15
0
        public void Create(ServiceView serviceView)
        {
            if (serviceView == null) throw new ArgumentNullException("serviceView");

            var service = serviceView.Convert();

            _dbContext.Services.Add(service);

            _dbContext.SaveChanges();
        }
コード例 #16
0
        public async Task <ActionResult> Create(ServiceView serviceView)
        {
            if (ModelState.IsValid)
            {
                var service = new Service(serviceView.ServiceName, serviceView.Price, serviceView.ServiceImageHref);
                await _servicesLogic.AddNewService(service);

                return(RedirectToAction("Index", new { message = Messages.CreateNewServiceSucces }));
            }
            return(View(serviceView));
        }
コード例 #17
0
        public void UpdateService(ServiceView service)
        {
            Services services = db.Services.Find(service.Id);

            services.ServiceName = service.ServiceName;
            services.Status      = service.Status;
            services.Price       = service.Price;
            services.Duration    = service.Duration;

            db.Entry(services).State = EntityState.Modified;
        }
コード例 #18
0
        public ServiceView GetService(int?id)
        {
            Services s = db.Services.Find(id);

            if (s == null)
            {
                return(null);
            }
            ServiceView service = mapper.Map <Services, ServiceView>(s);

            return(service);
        }
コード例 #19
0
        public WorkView(IClient c)
        {
            InitializeComponent();

            display  = new DisplayView(c);
            calendar = new CalendarView(c);
            modes    = new ModesView(c);
            charts   = new ChartsView(c);
            settings = new WorkViews.SettingsView(c);
            service  = new ServiceView(c);

            DataContext = display;
        }
コード例 #20
0
        // GET: Service/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ServiceView service = _serviceManager.GetService(id);

            if (service == null)
            {
                return(HttpNotFound());
            }
            return(View(service));
        }
コード例 #21
0
        public async Task <ActionResult <ServiceView> > CreateService(ServiceView serviceView)
        {
            var service = new Models.Service
            {
                ServiceId   = serviceView.ServiceId,
                ServiceName = serviceView.ServiceName,
                StartTime   = serviceView.StartTime,
                EndTime     = serviceView.EndTime,
                IsAvailable = serviceView.IsAvailable
            };

            _context.Services.Add(service);
            await _context.SaveChangesAsync();

            return(Ok(service));
        }
コード例 #22
0
        public ActionResult AddSerevice(ServiceView product)
        {
            _context.Dispose();
            Service temp = new Service();
            var     con  = new ApplicationDbContext();

            temp.Name              = product.Name;
            temp.Available         = product.Available;
            temp.Price             = product.Price;
            temp.AvailableLocation = product.AvailableLocation;
            temp.Category          = con.Categories.FirstOrDefault(c => c.Name == product.Category);
            temp.Vendor            = con.Users.Where(u => u.Id == product.Vendor).FirstOrDefault();
            con.Services.Add(temp);
            con.SaveChanges();
            return(RedirectToAction("Service", "Home"));
        }
コード例 #23
0
        public void Create(ServiceView serviceView, IEnumerable<string> permissions)
        {
            if (serviceView == null) throw new ArgumentNullException("serviceView");
            if (permissions == null) throw new ArgumentNullException("permissions");

            var service = serviceView.Convert();

            foreach (var permission in permissions)
                service.Permissions.Add(new ServicePermission()
                                            {
                                                Name = permission,
                                                Service = service
                                            });

            _dbContext.Services.Add(service);
            _dbContext.SaveChanges();
        }
コード例 #24
0
        public async Task <IActionResult> Edit(int serviceId)
        {
            var service_response = await _apiContext.GetRequest("Services/" + serviceId + "");

            var service_details = JsonConvert.DeserializeObject <Service>(service_response.Value.ToString());

            var employees_response = await _apiContext.GetRequest("Employees/");

            var employees_list = JsonConvert.DeserializeObject <List <Employee> >(employees_response.Value.ToString());

            var categories_response = await _apiContext.GetRequest("Categories/");

            var categories_list = JsonConvert.DeserializeObject <List <Category> >(categories_response.Value.ToString());

            var club = await _apiContext.GetRequest("Clubs/");

            var clubs_list = JsonConvert.DeserializeObject <List <Club> >(club.Value.ToString());

            var categories = categories_list.Where(c => service_details.Category_Id.Contains(c.Category_Id)).ToList();
            var employees  = employees_list.Where(e => service_details.Employee_Id.Contains(e.Employee_Id)).ToList();
            var clubs      = clubs_list.Where(c => service_details.Club_Id.Contains(c.Club_Id)).ToList();

            var result = new ServiceView()
            {
                Club                  = clubs,
                Category              = categories,
                Employee              = employees,
                Service_Description   = service_details.Service_Description,
                Service_Gross_Price   = service_details.Service_Gross_Price,
                Service_Id            = service_details.Service_Id,
                Service_Name          = service_details.Service_Name,
                Service_Net_Price     = service_details.Service_Net_Price,
                Service_Timelimit_Fri = service_details.Service_Timelimit_Fri,
                Service_Timelimit_Mon = service_details.Service_Timelimit_Mon,
                Service_Timelimit_Sat = service_details.Service_Timelimit_Sat,
                Service_Timelimit_Sun = service_details.Service_Timelimit_Sun,
                Service_Timelimit_Thu = service_details.Service_Timelimit_Thu,
                Service_Timelimit_Tue = service_details.Service_Timelimit_Tue,
                Service_Timelimit_Wed = service_details.Service_Timelimit_Wed,
                Service_Duration      = service_details.Service_Duration
            };

            return(View(result));
        }
コード例 #25
0
 public async Task<List<ServiceView>> GetAllServicesWithDiscount()
 {
     var result = new List<ServiceView>();
     var services = await _db.Services.Include(s => s.Discount).Where(s => s.DiscountId != null).ToListAsync();
     foreach (var service in services)
     {
         var tmpService = new ServiceView(service.ServiceId, service.ServiceName, service.Price, service.PriceWithDiscount, service.ServiceImageHref, service.Discount);
         if (service.Discount.isRelevant())
         {
             tmpService.DiscountRelevancy = true;
             result.Add(tmpService);
         }
         else
         {
             result.Add(tmpService);
         }
     }
     return result;
 }
コード例 #26
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            BookingView bookings = _bookingManager.GetBooking(id);
            UserView    user     = _userManager.findUserById(bookings.UserId);

            ViewBag.UserEmail = user.Email;
            VehicleView vehicle = _VehicleManager.getVehicle(bookings.VehicleId);

            ViewBag.LicensePlate = vehicle.LicensePlate;
            ServiceView service = _serviceManager.GetService(bookings.ServiceId);

            ViewBag.ServiceName = service.ServiceName;
            if (bookings == null)
            {
                return(HttpNotFound());
            }
            return(View(bookings));
        }
コード例 #27
0
        public App()
        {
            InitializeComponent();

            MainPage = new ServiceView();
        }
コード例 #28
0
        public async Task <IActionResult> Delete([DataSourceRequest] DataSourceRequest request, ServiceView service)
        {
            var existingService = await _context.Service.FindAsync(service.ServiceId).ConfigureAwait(false);

            if (existingService == null)
            {
                ModelState.AddModelError("Delete Error", "The service was already deleted!");
                return(BadRequest(ModelState));
            }

            _context.Service.Remove(existingService);
            await _context.SaveChangesAsync().ConfigureAwait(false);

            return(Ok(existingService));
        }
コード例 #29
0
        public async Task <IActionResult> Update([DataSourceRequest] DataSourceRequest request, ServiceView service)
        {
            var existingService = await _context.Service.FindAsync(service.ServiceId).ConfigureAwait(false);

            if (existingService == null)
            {
                ModelState.AddModelError("Not found!", "Service cannot be found!");
                return(BadRequest(ModelState));
            }

            if (!existingService.RowVersion.SequenceEqual(service.RowVersion))
            {
                ModelState.AddModelError("Concurrency Error", "Someone already made changes to this service. Please refresh!");
                return(BadRequest(ModelState));
            }

            existingService.ServiceName = service.ServiceName;
            await _context.SaveChangesAsync().ConfigureAwait(false);

            service.RowVersion = existingService.RowVersion;

            var result = await new[] { service }.ToDataSourceResultAsync(request).ConfigureAwait(false);
            var json = JsonConvert.SerializeObject(result);

            return(new ContentResult {
                Content = json, ContentType = Constants.JSON_MIME
            });
        }
コード例 #30
0
        //
        // GET: /Admin/
        public void Populate()
        {
            DataBaseManager.DropAndCreate();

            using (var dataBaseManager = new DataBaseManager())
            {
                #region CREATE_SERVICES

                var serviceManager = new ServiceManager(dataBaseManager);

                var serviceSvn = new ServiceView()
                                     {
                                         Name = "Svn",
                                         Description = "System Version Control (Centralized)"
                                     };

                serviceManager.Create(serviceSvn, new[] {"r", "rw"});

                #endregion

                #region CREATE_USERS

                var userManager = new UserManager(dataBaseManager);

                var userFaustino = new UserView()
                                       {
                                           Name = "FaustinoLeiras",
                                           Email = "*****@*****.**",
                                           Password = "******"
                                       };

                userManager.Create(userFaustino);

                var userSamir = new UserView()
                                    {
                                        Name = "SamirHafez",
                                        Email = "*****@*****.**",
                                        Password = "******"
                                    };

                userManager.Create(userSamir);

                var userRicardo = new UserView()
                                      {
                                          Name = "Ricardo",
                                          Email = "*****@*****.**",
                                          Password = "******"
                                      };

                userManager.Create(userRicardo);

                var userGeada = new UserView()
                                    {
                                        Name = "Gueada",
                                        Email = "*****@*****.**",
                                        Password = "******"
                                    };

                userManager.Create(userGeada);

                var userFelix = new UserView()
                                    {
                                        Name = "Felix",
                                        Email = "*****@*****.**",
                                        Password = "******"
                                    };

                userManager.Create(userFelix);

                var userGuedes = new UserView()
                                     {
                                         Name = "Guedes",
                                         Email = "*****@*****.**",
                                         Password = "******"
                                     };

                userManager.Create(userGuedes);

                #endregion

                #region CREATE_STRUCTURE

                var structureManager = new StructureManager(dataBaseManager);

                var structure = new StructureView()
                                    {
                                        Name = "AcademicStructure",
                                        Description = "My Academic Structure :)"
                                    };

                structureManager.Create(structure, userFaustino.Name);

                #endregion

                #region CREATE_WORKSPACE_TYPE

                var workspaceType = new WorkSpaceTypeManager(dataBaseManager);

                var workspacePublic = new WorkSpaceTypeView()
                                          {
                                              Name = "public"
                                          };

                workspaceType.Create(workspacePublic, structure.Id, new[] {serviceSvn.Name});

                var workspacePrivate = new WorkSpaceTypeView()
                                           {
                                               Name = "private"
                                           };

                workspaceType.Create(workspacePrivate, structure.Id, new[] {serviceSvn.Name});

                #endregion

                #region CREATE_CONTAINER_PROTOTYPE

                var containerPrototype = new ContainerPrototypeManager(dataBaseManager);

                var prototypeGraduation = new ContainerPrototypeView()
                                              {
                                                  Name = "Graduation"
                                              };

                containerPrototype.Create(prototypeGraduation, structure.Id);

                var prototypeCourse = new ContainerPrototypeView()
                                          {
                                              Name = "Course"
                                          };

                containerPrototype.Create(prototypeCourse, structure.Id, prototypeGraduation.Name);

                var prototypeClass = new ContainerPrototypeView()
                                         {
                                             Name = "Class"
                                         };

                containerPrototype.Create(prototypeClass, structure.Id, prototypeCourse.Name);

                var prototypeGroup = new ContainerPrototypeView()
                                         {
                                             Name = "Group"
                                         };

                containerPrototype.Create(prototypeGroup, structure.Id, prototypeClass.Name);

                #endregion

                #region ADD_WORKSPACE_TYPES_INTO_CONTAINER_PROTOTYPE

                containerPrototype.AddWorkSpaceType(structure.Id, prototypeGraduation.Name, workspacePublic.Name);

                containerPrototype.AddWorkSpaceType(structure.Id, prototypeCourse.Name, workspacePublic.Name);

                containerPrototype.AddWorkSpaceType(structure.Id, prototypeClass.Name, workspacePublic.Name);
                containerPrototype.AddWorkSpaceType(structure.Id, prototypeClass.Name, workspacePrivate.Name);

                containerPrototype.AddWorkSpaceType(structure.Id, prototypeGroup.Name, workspacePublic.Name);

                #endregion

                #region CREATE_ROLETYPE

                var roleType = new RoleTypeManager(dataBaseManager);

                var roleTypeTeacher = new RoleTypeView()
                                          {
                                              Name = "teacher"
                                          };

                roleType.Create(roleTypeTeacher, structure.Id);

                var roleTypeDirector = new RoleTypeView()
                                           {
                                               Name = "director"
                                           };

                roleType.Create(roleTypeDirector, structure.Id);

                var roleTypeStudant = new RoleTypeView()
                                          {
                                              Name = "studant"
                                          };

                roleType.Create(roleTypeStudant, structure.Id);

                #endregion

                #region CREATE_RULE

                var rule = new RuleManager(dataBaseManager);

                var ruleReaders = new RuleView()
                                      {
                                          Name = "readers"
                                      };

                rule.Create(ruleReaders, structure.Id, new[]
                                                           {
                                                               new KeyValuePair<string, string>(serviceSvn.Name, "r")
                                                           });

                var ruleReadersAndWriters = new RuleView()
                                                {
                                                    Name = "ReadersAndWriters"
                                                };

                rule.Create(ruleReadersAndWriters, structure.Id, new[]
                                                                     {
                                                                         new KeyValuePair<string, string>(
                                                                             serviceSvn.Name,
                                                                             "rw")
                                                                     });

                #endregion

                #region CREATE_ROLE

                var role = new RoleManager(dataBaseManager);

                #region ADD_ROLES_COURSE_WORKSPACE_PUBLIC

                role.Create(
                    structure.Id,
                    prototypeCourse.Name,
                    workspacePublic.Name,
                    roleTypeDirector.Name,
                    ruleReadersAndWriters.Name
                    );

                role.Create(
                    structure.Id,
                    prototypeCourse.Name,
                    workspacePublic.Name,
                    roleTypeTeacher.Name,
                    ruleReaders.Name
                    );

                role.Create(
                    structure.Id,
                    prototypeCourse.Name,
                    workspacePublic.Name,
                    roleTypeStudant.Name,
                    ruleReaders.Name
                    );

                #endregion

                #region ADD_ROLES_CLASS_WORKSPACE_PUBLIC

                role.Create(
                    structure.Id,
                    prototypeClass.Name,
                    workspacePublic.Name,
                    roleTypeDirector.Name,
                    ruleReaders.Name
                    );

                role.Create(
                    structure.Id,
                    prototypeClass.Name,
                    workspacePublic.Name,
                    roleTypeTeacher.Name,
                    ruleReadersAndWriters.Name
                    );

                role.Create(
                    structure.Id,
                    prototypeClass.Name,
                    workspacePublic.Name,
                    roleTypeStudant.Name,
                    ruleReaders.Name
                    );

                #endregion

                #region ADD_ROLES_CLASS_WORKSPACE_PRIVATE

                role.Create(
                    structure.Id,
                    prototypeClass.Name,
                    workspacePrivate.Name,
                    roleTypeDirector.Name,
                    ruleReaders.Name
                    );

                role.Create(
                    structure.Id,
                    prototypeClass.Name,
                    workspacePrivate.Name,
                    roleTypeTeacher.Name,
                    ruleReadersAndWriters.Name
                    );

                #endregion

                #region ADD_ROLES_GROUP_WORKSPACE_PUBLIC

                role.Create(
                    structure.Id,
                    prototypeGroup.Name,
                    workspacePublic.Name,
                    roleTypeDirector.Name,
                    ruleReaders.Name
                    );

                role.Create(
                    structure.Id,
                    prototypeGroup.Name,
                    workspacePublic.Name,
                    roleTypeTeacher.Name,
                    ruleReadersAndWriters.Name
                    );

                role.Create(
                    structure.Id,
                    prototypeGroup.Name,
                    workspacePublic.Name,
                    roleTypeStudant.Name,
                    ruleReadersAndWriters.Name
                    );

                #endregion

                #endregion
            }
        }
コード例 #31
0
 public void UpdateService(ServiceView service)
 {
     _serviceRepository.UpdateService(service);
 }
コード例 #32
0
 public void AddService(ServiceView service)
 {
     _serviceRepository.AddService(service);
 }
コード例 #33
0
        public void ShouldTestBasicFeatures()
        {
            DataBaseManager.Initializer();
            using (var dataBaseManager = new DataBaseManager())
            {
                #region CREATE_SERVICES

                var serviceManager = new ServiceManager(dataBaseManager);

                var serviceGit = new ServiceView()
                                     {
                                         Name = "Git",
                                         Description = "System Version Control (decentralized)"
                                     };

                serviceManager.Create(serviceGit, new[] {"r", "rw"});

                var serviceSvn = new ServiceView()
                                     {
                                         Name = "Svn",
                                         Description = "System Version Control (Centralized)"
                                     };

                serviceManager.Create(serviceSvn, new[] {"r", "rw"});

                #endregion

                #region CREATE_USERS

                var userManager = new UserManager(dataBaseManager);

                var userFaustino = new UserView()
                                       {
                                           Name = "FaustinoLeiras",
                                           Email = "*****@*****.**",
                                           Password = "******"
                                       };

                userManager.Create(userFaustino);

                var userSamir = new UserView()
                                    {
                                        Name = "SamirHafez",
                                        Email = "*****@*****.**",
                                        Password = "******"
                                    };

                userManager.Create(userSamir);

                var userRicardo = new UserView()
                                      {
                                          Name = "Ricardo",
                                          Email = "*****@*****.**",
                                          Password = "******"
                                      };

                userManager.Create(userRicardo);

                var userGeada = new UserView()
                                    {
                                        Name = "Gueada",
                                        Email = "*****@*****.**",
                                        Password = "******"
                                    };

                userManager.Create(userGeada);

                var userFelix = new UserView()
                                    {
                                        Name = "Felix",
                                        Email = "*****@*****.**",
                                        Password = "******"
                                    };

                userManager.Create(userFelix);

                var userGuedes = new UserView()
                                     {
                                         Name = "Guedes",
                                         Email = "*****@*****.**",
                                         Password = "******"
                                     };

                userManager.Create(userGuedes);

                #endregion

                #region CREATE_STRUCTURE

                var structureManager = new StructureManager(dataBaseManager);

                var structure = new StructureView()
                                    {
                                        Name = "AcademicStructure",
                                        Description = "My Academic Structure :)"
                                    };

                structureManager.Create(structure, userFaustino.Name);

                #endregion

                #region CREATE_WORKSPACE_TYPE

                var workspaceType = new WorkSpaceTypeManager(dataBaseManager);

                var workspacePublic = new WorkSpaceTypeView()
                                          {
                                              Name = "public"
                                          };

                workspaceType.Create(workspacePublic, structure.Id, new[] {serviceGit.Name, serviceSvn.Name});

                var workspacePrivate = new WorkSpaceTypeView()
                                           {
                                               Name = "private"
                                           };

                workspaceType.Create(workspacePrivate, structure.Id, new[] {serviceGit.Name, serviceSvn.Name});

                #endregion

                #region CREATE_CONTAINER_PROTOTYPE

                var containerPrototype = new ContainerPrototypeManager(dataBaseManager);

                var prototypeGraduation = new ContainerPrototypeView()
                                              {
                                                  Name = "Graduation"
                                              };

                containerPrototype.Create(prototypeGraduation, structure.Id);

                var prototypeCourse = new ContainerPrototypeView()
                                          {
                                              Name = "Course"
                                          };

                containerPrototype.Create(prototypeCourse, structure.Id, prototypeGraduation.Name);

                var prototypeClass = new ContainerPrototypeView()
                                         {
                                             Name = "Class"
                                         };

                containerPrototype.Create(prototypeClass, structure.Id, prototypeCourse.Name);

                var prototypeGroup = new ContainerPrototypeView()
                                         {
                                             Name = "Group"
                                         };

                containerPrototype.Create(prototypeGroup, structure.Id, prototypeClass.Name);

                #endregion

                #region ADD_WORKSPACE_TYPES_INTO_CONTAINER_PROTOTYPE

                containerPrototype.AddWorkSpaceType(structure.Id, prototypeGraduation.Name, workspacePublic.Name);

                containerPrototype.AddWorkSpaceType(structure.Id, prototypeCourse.Name, workspacePublic.Name);

                containerPrototype.AddWorkSpaceType(structure.Id, prototypeClass.Name, workspacePublic.Name);
                containerPrototype.AddWorkSpaceType(structure.Id, prototypeClass.Name, workspacePrivate.Name);

                containerPrototype.AddWorkSpaceType(structure.Id, prototypeGroup.Name, workspacePublic.Name);

                #endregion

                #region CREATE_ROLETYPE

                var roleType = new RoleTypeManager(dataBaseManager);

                var roleTypeTeacher = new RoleTypeView()
                                          {
                                              Name = "teacher"
                                          };

                roleType.Create(roleTypeTeacher, structure.Id);

                var roleTypeDirector = new RoleTypeView()
                                           {
                                               Name = "director"
                                           };

                roleType.Create(roleTypeDirector, structure.Id);

                var roleTypeStudant = new RoleTypeView()
                                          {
                                              Name = "studant"
                                          };

                roleType.Create(roleTypeStudant, structure.Id);

                #endregion

                #region CREATE_RULE

                var rule = new RuleManager(dataBaseManager);

                var ruleReaders = new RuleView()
                                      {
                                          Name = "readers"
                                      };

                rule.Create(ruleReaders, structure.Id, new[]
                                                           {
                                                               new KeyValuePair<string, string>(serviceGit.Name, "r"),
                                                               new KeyValuePair<string, string>(serviceSvn.Name, "r")
                                                           });

                var ruleReadersAndWriters = new RuleView()
                                                {
                                                    Name = "ReadersAndWriters"
                                                };

                rule.Create(ruleReadersAndWriters, structure.Id, new[]
                                                                     {
                                                                         new KeyValuePair<string, string>(
                                                                             serviceGit.Name,
                                                                             "rw"),
                                                                         new KeyValuePair<string, string>(
                                                                             serviceSvn.Name,
                                                                             "rw")
                                                                     });

                #endregion

                #region CREATE_ROLE

                var role = new RoleManager(dataBaseManager);

                #region ADD_ROLES_COURSE_WORKSPACE_PUBLIC

                role.Create(
                    structure.Id,
                    prototypeCourse.Name,
                    workspacePublic.Name,
                    roleTypeDirector.Name,
                    ruleReadersAndWriters.Name
                    );

                role.Create(
                    structure.Id,
                    prototypeCourse.Name,
                    workspacePublic.Name,
                    roleTypeTeacher.Name,
                    ruleReaders.Name
                    );

                role.Create(
                    structure.Id,
                    prototypeCourse.Name,
                    workspacePublic.Name,
                    roleTypeStudant.Name,
                    ruleReaders.Name
                    );

                #endregion

                #region ADD_ROLES_CLASS_WORKSPACE_PUBLIC

                role.Create(
                    structure.Id,
                    prototypeClass.Name,
                    workspacePublic.Name,
                    roleTypeDirector.Name,
                    ruleReaders.Name
                    );

                role.Create(
                    structure.Id,
                    prototypeClass.Name,
                    workspacePublic.Name,
                    roleTypeTeacher.Name,
                    ruleReadersAndWriters.Name
                    );

                role.Create(
                    structure.Id,
                    prototypeClass.Name,
                    workspacePublic.Name,
                    roleTypeStudant.Name,
                    ruleReaders.Name
                    );

                #endregion

                #region ADD_ROLES_CLASS_WORKSPACE_PRIVATE

                role.Create(
                    structure.Id,
                    prototypeClass.Name,
                    workspacePrivate.Name,
                    roleTypeDirector.Name,
                    ruleReaders.Name
                    );

                role.Create(
                    structure.Id,
                    prototypeClass.Name,
                    workspacePrivate.Name,
                    roleTypeTeacher.Name,
                    ruleReadersAndWriters.Name
                    );

                #endregion

                #region ADD_ROLES_GROUP_WORKSPACE_PUBLIC

                role.Create(
                    structure.Id,
                    prototypeGroup.Name,
                    workspacePublic.Name,
                    roleTypeDirector.Name,
                    ruleReaders.Name
                    );

                role.Create(
                    structure.Id,
                    prototypeGroup.Name,
                    workspacePublic.Name,
                    roleTypeTeacher.Name,
                    ruleReadersAndWriters.Name
                    );

                role.Create(
                    structure.Id,
                    prototypeGroup.Name,
                    workspacePublic.Name,
                    roleTypeStudant.Name,
                    ruleReadersAndWriters.Name
                    );

                #endregion

                #endregion

                #region CREATE_CONTAINERS

                var container = new ContainerManager(dataBaseManager);

                var containerLeic = new ContainerView()
                                        {
                                            Name = "LEIC",
                                            Description = "Licencitura Egenharia informatica e de computadores"
                                        };

                container.Create(containerLeic, structure.Id, prototypeGraduation.Name);

                #region CREATE_COURSE_MPD

                var containerMpd = new ContainerView()
                                       {
                                           Name = "MPD",
                                           Description = "Modelo de padoes de desenho"
                                       };

                container.Create(containerMpd, structure.Id, prototypeCourse.Name, containerLeic.Id);

                var containerMpdLi31D = new ContainerView()
                                            {
                                                Name = "LI31D",
                                                Description = "Turma 1 de terceiro semestre diurno"
                                            };

                container.Create(containerMpdLi31D, structure.Id, prototypeClass.Name, containerMpd.Id);

                var containerMpdG1 = new ContainerView()
                                         {
                                             Name = "Grupo1",
                                             Description = "Grupo de MPD"
                                         };

                container.Create(containerMpdG1, structure.Id, prototypeGroup.Name, containerMpdLi31D.Id);

                var containerMpdG2 = new ContainerView()
                                         {
                                             Name = "Grupo2",
                                             Description = "Grupo de MPD"
                                         };

                container.Create(containerMpdG2, structure.Id, prototypeGroup.Name, containerMpdLi31D.Id);

                #endregion

                #region CREATE_COURSE_SD

                var containerSd = new ContainerView()
                                      {
                                          Name = "SD",
                                          Description = "Sistemas distribuidos"
                                      };

                container.Create(containerSd, structure.Id, prototypeCourse.Name, containerLeic.Id);

                var containerSdLi31D = new ContainerView()
                                           {
                                               Name = "LI31D",
                                               Description = "Turma 1 de terceiro semestre diurno"
                                           };

                container.Create(containerSdLi31D, structure.Id, prototypeClass.Name, containerSd.Id);

                var containerSdG1 = new ContainerView()
                                        {
                                            Name = "Grupo1",
                                            Description = "Grupo de SD"
                                        };

                container.Create(containerSdG1, structure.Id, prototypeGroup.Name, containerSdLi31D.Id);

                var containerSdG2 = new ContainerView()
                                        {
                                            Name = "Grupo2",
                                            Description = "Grupo de SD"
                                        };

                container.Create(containerSdG2, structure.Id, prototypeGroup.Name, containerSdLi31D.Id);

                #endregion

                #endregion

                #region ENROLL_USER

                userManager.Enroll(userFelix.Name, structure.Id, containerLeic.Id, roleTypeDirector.Name);

                userManager.Enroll(userFelix.Name, structure.Id, containerMpd.Id, roleTypeDirector.Name);
                userManager.Enroll(userGuedes.Name, structure.Id, containerSd.Id, roleTypeDirector.Name);

                userManager.Enroll(userFelix.Name, structure.Id, containerSdLi31D.Id, roleTypeTeacher.Name);
                userManager.Enroll(userGuedes.Name, structure.Id, containerMpdLi31D.Id, roleTypeTeacher.Name);

                userManager.Enroll(userFaustino.Name, structure.Id, containerMpdG1.Id, roleTypeStudant.Name);
                userManager.Enroll(userSamir.Name, structure.Id, containerMpdG1.Id, roleTypeStudant.Name);

                userManager.Enroll(userRicardo.Name, structure.Id, containerMpdG2.Id, roleTypeStudant.Name);
                userManager.Enroll(userGeada.Name, structure.Id, containerMpdG2.Id, roleTypeStudant.Name);

                userManager.Enroll(userFaustino.Name, structure.Id, containerSdG1.Id, roleTypeStudant.Name);
                userManager.Enroll(userRicardo.Name, structure.Id, containerSdG1.Id, roleTypeStudant.Name);

                userManager.Enroll(userGeada.Name, structure.Id, containerSdG2.Id, roleTypeStudant.Name);
                userManager.Enroll(userSamir.Name, structure.Id, containerSdG2.Id, roleTypeStudant.Name);

                #endregion

                //AuthorizationTestes aut = new AuthorizationTestes();
                //AuthorizationManager authorizationManager = new AuthorizationManager(dataBaseManager);

                //authorizationManager.CreateServiceAuthorizationStruct(aut, serviceSvn.Name);
            }
        }
コード例 #34
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (userchanged)
            {
                logedinuser.Text = ". Tasks will run with the user:"******"\\" + username;
            }

            //Connect to SCOM
            ManagementGroup mg = new ManagementGroup(msserver);

            if (!(mg.IsConnected))
            {
                Server.Transfer("~/ErrorPage.aspx?Error=6");
            }

            string query = "DisplayName = '" + System.Configuration.ConfigurationManager.AppSettings["GetServices"] + "'";
            ManagementPackTaskCriteria taskCriteria = new ManagementPackTaskCriteria(query);
            IList <ManagementPackTask> tasks        =
                mg.TaskConfiguration.GetTasks(taskCriteria);
            ManagementPackTask task = null;

            if (tasks.Count == 1)
            {
                task = tasks[0];
            }
            else
            {
                Server.Transfer("~/ErrorPage.aspx?Error=2");
            }

            // Get the agent class.
            query = "Name = 'Microsoft.Windows.Computer'";
            ManagementPackClassCriteria criteria = new ManagementPackClassCriteria(query);

            IList <ManagementPackClass> classes =
                mg.EntityTypes.GetClasses(criteria);

            if (classes.Count != 1)
            {
                Server.Transfer("~/ErrorPage.aspx?Error=5");
            }

            // Create a MonitoringObject list containing a specific agent (the
            // target of the task).
            string fullAgentName;

            if (Request.QueryString["id"] == null && Request.QueryString["DisplayName"] == null)
            {
                Server.Transfer("~/ErrorPage.aspx?Error=1");
            }
            else if (Request.QueryString["id"] != null)
            {
                fullAgentName = Request.QueryString["id"];
                query         = "Id = '" + fullAgentName + "'";
                objectid      = fullAgentName;
            }
            else if (Request.QueryString["DisplayName"] != null)
            {
                fullAgentName = Request.QueryString["DisplayName"];
                query         = "DisplayName = '" + fullAgentName + "'";
                objectid      = fullAgentName;
            }
            else
            {
                //to be developed
            }

            List <MonitoringObject>  targets        = new List <MonitoringObject>();
            MonitoringObjectCriteria targetCriteria =
                new MonitoringObjectCriteria(query, classes[0]);

            targets.AddRange(mg.EntityObjects.GetObjectReader <MonitoringObject>(targetCriteria, ObjectQueryOptions.Default));
            if (targets.Count != 1)
            {
                Server.Transfer("~/ErrorPage.aspx?Error=3");
            }

            //Get user filter options
            Microsoft.EnterpriseManagement.Runtime.TaskConfiguration config = new Microsoft.EnterpriseManagement.Runtime.TaskConfiguration();

            try
            {
                IList <Microsoft.EnterpriseManagement.Configuration.ManagementPackOverrideableParameter> overrideparams = task.GetOverrideableParameters();
                //user Service State Filter
                string State = Request.QueryString["state"];
                State = $"($_.startmode -match \"{State}\")";
                //user Service Status filter
                string Status = Request.QueryString["status"];
                Status = $"($_.state -match \"{Status}\")";
                //user Service Name like filter
                string ServiceName = Request.QueryString["name"];
                //user Service sorting
                string Sort          = Request.QueryString["sort"];
                string overridevalue = "";
                if (ServiceName != null)
                {
                    overridevalue = $"gwmi -Query \"select * from win32_service where name like '%{ServiceName}%'\" | select displayname,name,startmode,state";
                }
                else
                {
                    overridevalue = "gwmi -Query \"select * from win32_service\" | select displayname,name,startmode,state";
                }

                if ((Request.QueryString["state"] != null) && (Request.QueryString["status"]) != null)
                {
                    overridevalue += "| ?{" + State + " -and " + Status + "}";
                }
                else if ((Request.QueryString["state"] != null))
                {
                    overridevalue += "| ?{" + State + "}";
                }
                else if ((Request.QueryString["status"] != null))
                {
                    overridevalue += "| ?{" + Status + "}";
                }
                else
                {
                    //do nothing
                }


                if ((Request.QueryString["sort"] != null))
                {
                    string sort = Request.QueryString["sort"];
                    sort          = sort.Replace("|", ",");
                    overridevalue = overridevalue + "| sort " + sort;
                }
                else
                {
                    overridevalue = overridevalue + "| sort-object -property @{Expression = {$_.State}; Ascending = $false},startmode ,name";
                }


                config.Overrides.Add(new Pair <ManagementPackOverrideableParameter, string>(overrideparams[1], overridevalue));
            }
            catch
            {
                Server.Transfer("~/ErrorPage.aspx?Error=7");
            }
            // Run the task.

            try
            {
                IList <Microsoft.EnterpriseManagement.Runtime.TaskResult> results =
                    mg.TaskRuntime.ExecuteTask(targets, task, config);
                if (results.Count == 0)
                {
                    Server.Transfer("~/ErrorPage.aspx?Error=4");
                }


                // Display the task results.
                int resultNo = 0;
                foreach (Microsoft.EnterpriseManagement.Runtime.TaskResult res in results)
                {
                    resultNo++;
                    if (res.Status == Microsoft.EnterpriseManagement.Runtime.TaskStatus.Failed)
                    {
                    }
                    else
                    {
                        //convert task result
                        XmlDocument xmlDoc = new XmlDocument();
                        xmlDoc.LoadXml(res.Output);
                        string             xPathQry        = @"/DataItem/Description";
                        System.Xml.XmlNode TaskDescription = xmlDoc.SelectSingleNode(xPathQry);
                        string             Servicelist     = TaskDescription.OuterXml.ToString();
                        Servicelist = Servicelist.Replace("<Description>", "").Replace("</Description>", "");
                        // put result in table
                        //DataTable dt = new DataTable();
                        dt.Columns.AddRange(new DataColumn[4] {
                            new DataColumn("Name", typeof(string)),
                            new DataColumn("DisplayName", typeof(string)),
                            new DataColumn("StartType", typeof(string)),
                            new DataColumn("Status", typeof(string))
                        });



                        //Read the contents of CSV file.
                        string csvData = Servicelist;

                        string test = csvData.Split('\r')[0].ToString();

                        if (test == "<Description />")
                        {
                            Server.Transfer("~/ErrorPage.aspx?Error=7");
                        }


                        string[] stringSeparators = new string[] { "\r\n" };

                        foreach (string row in csvData.Split(stringSeparators, StringSplitOptions.None))
                        {
                            int i = 0;
                            try
                            {
                                if (!string.IsNullOrEmpty(row))
                                {
                                    dt.Rows.Add();
                                    dt.Rows[dt.Rows.Count - 1][0] = row.Split(',')[0];
                                    dt.Rows[dt.Rows.Count - 1][1] = row.Split(',')[1];
                                    dt.Rows[dt.Rows.Count - 1][2] = row.Split(',')[2];
                                    dt.Rows[dt.Rows.Count - 1][3] = row.Split(',')[3].Replace(";", "");

                                    i++;
                                }
                                string privrew = row.ToString();
                            }
                            catch
                            {
                            }
                        }

                        ServiceView.DataSource = dt;
                        ServiceView.DataBind();
                    }
                }
            }
            catch
            {
                Server.Transfer("~/ErrorPage.aspx?Error=0");
            }
        }