예제 #1
0
        private static List <string> GenerateComputerUsers(int computerId)
        {
            var userNames  = new List <string>();
            var userAmount = Settings.MaxAmountOfComputerUsers.Random(3);
            var names      = GenerateUniqueUserNames(userAmount);

            for (var i = 0; i < userAmount; i++)
            {
                var computerUser = new ComputerUser
                {
                    ComputerId     = computerId,
                    Name           = names.ElementAtOrDefault(i),
                    FullName       = names.ElementAtOrDefault(i),
                    PrivilegeLevel = i == 0 ? "Administrator" : (3.Random() == 0 ? "Administrator" : "Standard user")
                };
                Db.ComputerUsers.Add(computerUser);
                Db.SaveChanges();
                LocalLogger.Log($"              Computer user {computerUser.Name} of type {computerUser.PrivilegeLevel} added");
                //LocalLogger.Log($"              Account type {computerUser.PrivilegeLevel}");
                GenerateBlockedApps(computerUser.ComputerUserId);
                GenerateBlockedSites(computerUser.ComputerUserId);
                LocalLogger.Log();
                _computerUsersCounter++;
                userNames.Add(computerUser.Name);
            }
            return(userNames);
        }
예제 #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            ComputerUser computerUser = db.ComputerUsers.Find(id);

            db.ComputerUsers.Remove(computerUser);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public IActionResult PostComputerUser([FromBody] ComputerUser computerUser)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            icomputerUser.AddComputerUser(computerUser);

            return(CreatedAtAction("GetComputerUser", new { id = computerUser.UserId }, computerUser));
        }
예제 #4
0
        public void AddComputerUser(ComputerUser computerUser)
        {
            var userid  = _context.User.Max(m => m.UserId);
            var comuser = _context.ComputerUser.Where(s => s.Uuid == computerUser.Uuid && s.UserId == userid);

            if (comuser == null)
            {
                computerUser.UserId = userid;
                _context.ComputerUser.Add(computerUser);
            }
        }
예제 #5
0
 public ActionResult Edit([Bind(Include = "ComputerUserId,Removed,ComputerId,Name,FullName,PrivilegeLevel")] ComputerUser computerUser)
 {
     if (ModelState.IsValid)
     {
         db.Entry(computerUser).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ComputerId = new SelectList(db.Computers, "ComputerId", "Name", computerUser.ComputerId);
     return(View(computerUser));
 }
예제 #6
0
 public static ComputerUserResource ToResource(this ComputerUser computerUser)
 {
     return(new ComputerUserResource()
     {
         Name = computerUser.Name,
         FullName = computerUser.FullName,
         PrivilegeLevel = computerUser.PrivilegeLevel,
         Removed = computerUser.Removed,
         ComputerUserId = computerUser.ComputerUserId,
         ComputerId = computerUser.ComputerId
     });
 }
예제 #7
0
        // GET: TempComputerUsers/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ComputerUser computerUser = db.ComputerUsers.Find(id);

            if (computerUser == null)
            {
                return(HttpNotFound());
            }
            return(View(computerUser));
        }
예제 #8
0
        // GET: TempComputerUsers/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ComputerUser computerUser = db.ComputerUsers.Find(id);

            if (computerUser == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ComputerId = new SelectList(db.Computers, "ComputerId", "Name", computerUser.ComputerId);
            return(View(computerUser));
        }
        public IActionResult PutComputerUser([FromRoute] int id, [FromBody] ComputerUser computerUser)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != computerUser.UserId)
            {
                return(BadRequest());
            }

            icomputerUser.PutComputerUser(id, computerUser);

            return(NoContent());
        }
예제 #10
0
 public void PutComputerUser(int id, ComputerUser computerUser)
 {
     _context.Entry(computerUser).State = EntityState.Modified;
 }
예제 #11
0
        public string AddComputer(Computer computer)
        {
            try
            {
                string result     = "";
                var    computerid = _context.Computer.SingleOrDefault(a => a.Uuid == computer.Uuid);
                if (computerid == null)
                {
                    _context.Computer.Add(computer);
                    ComputerUser computerUser = new ComputerUser();
                    computerUser.Uuid   = computer.Uuid;
                    computerUser.UserId = computer.UserId;
                    _context.ComputerUser.Add(computerUser);
                    _context.SaveChanges();
                    result = "Create New User";
                }
                else
                {
                    //------------------------------------Remove Memory  -----------------------//
                    var memoryall = _context.Memory.Where(s => s.Uuid == computer.Uuid);
                    _context.Memory.RemoveRange(memoryall);
                    _context.SaveChanges();
                    //----------------------------------End Remove Memory -----------------------//
                    //-------------------------------------Remove DiskDrive-----------------------//
                    var diskdriveall = _context.DiskDrive.Where(s => s.Uuid == computer.Uuid);
                    _context.DiskDrive.RemoveRange(diskdriveall);
                    _context.SaveChanges();
                    //----------------------------------End Remove DiskDrive -----------------------//
                    //----------------------------------Remove GraphicCard -----------------------//

                    var graphicCard = _context.GraphicCard.Where(s => s.Uuid == computer.Uuid);
                    _context.GraphicCard.RemoveRange(graphicCard);
                    _context.SaveChanges();
                    //---------------------------------End Remove GraphicCard -----------------------//
                    foreach (var memory in computer.Memory)
                    {
                        memory.Uuid = computer.Uuid;
                        _context.Memory.Add(memory);
                        _context.SaveChanges();
                    }
                    foreach (var diskdrive in computer.DiskDrive)
                    {
                        diskdrive.Uuid = computer.Uuid;
                        _context.DiskDrive.Add(diskdrive);
                        _context.SaveChanges();
                    }
                    foreach (var graphiccard in computer.GraphicCard)
                    {
                        graphiccard.Uuid = computer.Uuid;
                        _context.GraphicCard.Add(graphiccard);
                        _context.SaveChanges();
                    }
                    var comuser = _context.ComputerUser.SingleOrDefault(s => s.Uuid == computer.Uuid);
                    if (comuser != null)
                    {
                        computerid.LastUpdate            = computer.LastUpdate;
                        _context.Entry(computerid).State = EntityState.Modified;
                        _context.SaveChanges();
                        var userid = _context.User.SingleOrDefault(a => a.UserId == computer.UserId);
                        if (userid.UserId != comuser.UserId)
                        {
                            var user = _context.User.SingleOrDefault(a => a.UserId == comuser.UserId);
                            user.UserName = userid.UserName;
                            _context.Entry(user).State = EntityState.Modified;
                            var unew = _context.ComputerUser.SingleOrDefault(s => s.UserId == userid.UserId);
                            if (unew == null)
                            {
                                _context.User.Remove(userid);
                                _context.SaveChanges();
                            }

                            result = "Update User :"******"Update User :"******"Suscess " + result);
            }
            catch (Exception ex)
            {
                return(Convert.ToString(ex));
            }
        }