public async Task <ActionResult> PostUserSoftware(UserSoftwareViewModel newuserSoftware) { if (ModelState.IsValid) { var userSoftware = new UserSoftware(); userSoftware.TimeStamp = DateTime.Now; var a = _context.Add(userSoftware); await _context.SaveChangesAsync(); var UserSoftwareId = _context.UserSoftware.OrderBy(x => x.Id).LastOrDefault(); for (int i = 0; i < newuserSoftware.runningSoftwares.Count; i++) { var runningSoftwares = new RunningSoftwares(); foreach (var item in newuserSoftware.runningSoftwares) { runningSoftwares.Name = item.name; runningSoftwares.DateInstalled = item.dateInstalled; runningSoftwares.Version = item.version; runningSoftwares.MainSoftwareId = UserSoftwareId.Id; } var b = _context.Add(runningSoftwares); } await _context.SaveChangesAsync(); return(CreatedAtAction("GetUserSoftware", new { id = userSoftware.Id }, newuserSoftware)); } return(Ok()); }
public async Task <IActionResult> PutUserSoftware([FromRoute] string id, [FromBody] UserSoftware userSoftware) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != userSoftware.UserName) { return(BadRequest()); } _context.Entry(userSoftware).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserSoftwareExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutUserSoftware(int id, UserSoftware userSoftware) { if (id != userSoftware.Id) { return(BadRequest()); } _context.Entry(userSoftware).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserSoftwareExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PostUserSoftware([FromBody] UserSoftware userSoftware) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.UserSoftware.Add(userSoftware); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (UserSoftwareExists(userSoftware.UserName)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetUserSoftware", new { id = userSoftware.UserName }, userSoftware)); }