public async Task <IActionResult> UploadCert(IFormFile file) { var fileStream = file.OpenReadStream(); var hash = SaveFileToFs(fileStream); var certBytes = new byte[fileStream.Length]; fileStream.Position = 0; fileStream.Read(certBytes, 0, (int)fileStream.Length); var cert = new X509Certificate2(certBytes); var dbFile = await _db.Files.FirstOrDefaultAsync(x => x.Md5Hash == hash); if (dbFile == null) { dbFile = new DbFile() { CreateDate = DateTime.UtcNow, Md5Hash = hash, Type = EFileType.Cert }; _db.Files.Add(dbFile); await _db.SaveChangesAsync(); } return(Ok(new CertUploadResult() { Id = dbFile.Id, Hash = hash, Issuer = cert.Issuer, NotAfter = cert.NotAfter, NotBefore = cert.NotBefore, })); }
public async Task <IActionResult> Create([Bind("Id,Batch,Year")] Batches batches) { if (ModelState.IsValid) { _context.Add(batches); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(batches)); }
public async Task <IActionResult> Create([Bind("Id,Name,Duration")] Courses courses) { if (ModelState.IsValid) { _context.Add(courses); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(courses)); }
public async Task <IActionResult> Create(Student nst) { if (ModelState.IsValid) { _db.Add(nst); await _db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(nst)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,UserName,Password")] User user) { if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(user)); }
public async Task <IActionResult> AddEmployee([FromBody] EmployeeDt employee) { employee.Id = 0; employee.Passport.Id = 0; employee.TaxId.Id = 0; var dbEmployee = _mapper.Map <DbEmployee>(employee); _db.Employees.Add(dbEmployee); await _db.SaveChangesAsync().ConfigureAwait(false); return(Ok(_mapper.Map <EmployeeDt>(dbEmployee))); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,CoursesID,BatchesID,PhoneNumber")] Registration registration) { if (ModelState.IsValid) { _context.Add(registration); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["BatchesID"] = new SelectList(_context.BatchTable, "Id", "Id", registration.BatchesID); ViewData["CoursesID"] = new SelectList(_context.CourseTable, "Id", "Name", registration.CoursesID); return(View(registration)); }
public async Task <IActionResult> DelAction(long id) { var dbAction = await _db.DeviceActions.FirstOrDefaultAsync(x => x.Id == id).ConfigureAwait(false); if (dbAction == null) { return(NotFound()); } _db.DeviceActions.Remove(dbAction); await _db.SaveChangesAsync().ConfigureAwait(false); return(Ok()); }
public async Task <IActionResult> DelPassport(long id) { var passport = await _db.Passports.FirstOrDefaultAsync(x => x.Id == id); if (passport == null) { return(NotFound()); } _db.Passports.Remove(passport); await _db.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> Add([FromBody] string name) { if (await _db.DeviceActionTypes.AnyAsync(x => x.Name == name).ConfigureAwait(false)) { return(Conflict("Type already created")); } _db.DeviceActionTypes.Add(new DbDeviceActionType() { Name = name }); await _db.SaveChangesAsync().ConfigureAwait(false); return(Ok()); }
public async Task <IActionResult> DelSoft(long id) { var dbSoftware = await _db.Softwares.FirstOrDefaultAsync(x => x.Id == id); if (dbSoftware == null) { return(NotFound()); } _db.Softwares.Remove(dbSoftware); await _db.SaveChangesAsync(); return(Ok()); }
public int removeAltelier(long Id) { int retour = 0; using (var db = new ManagementDbContext()) { try { var altelier = db.Alteliers.Find(Id); db.Alteliers.Remove(altelier); db.SaveChangesAsync(); retour = 1; } catch (Exception e) { retour = 0; } } return(retour); }
public async Task <IActionResult> Update(long id, [FromBody] TaxIdUpdate upd, [FromServices] IMapper mapper) { var dbTaxId = await _db.TaxIds.FirstOrDefaultAsync(x => x.Id == id).ConfigureAwait(false); if (dbTaxId == null) { return(NotFound()); } if (upd.SerialNumber != null && dbTaxId.SerialNumber != upd.SerialNumber) { dbTaxId.SerialNumber = upd.SerialNumber; } if (upd.ScanFileId != 0 && dbTaxId.ScanFileId != upd.ScanFileId) { dbTaxId.ScanFileId = upd.ScanFileId; } _db.TaxIds.Update(dbTaxId); await _db.SaveChangesAsync().ConfigureAwait(false); return(Ok(mapper.Map <TaxId>(dbTaxId))); }