Beispiel #1
0
        public async Task <IActionResult> PutLogin([FromRoute] int id, [FromBody] Login login)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            _context.Entry(login).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LoginExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #2
0
 public void PutGraphicCard(int id, GraphicCard graphicCard)
 {
     _context.Entry(graphicCard).State = EntityState.Modified;
 }
 public void PutUser(int id, User user)
 {
     _context.Entry(user).State = EntityState.Modified;
 }
Beispiel #4
0
 public void PutDiskDrive(int id, DiskDrive diskDrive)
 {
     _context.Entry(diskDrive).State = EntityState.Modified;
 }
 public void PutMemory(int id, Memory memory)
 {
     _context.Entry(memory).State = EntityState.Modified;
 }
Beispiel #6
0
 public void PutComputerUser(int id, ComputerUser computerUser)
 {
     _context.Entry(computerUser).State = EntityState.Modified;
 }
        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));
            }
        }