// public async Task<ActionResult<MemberFileDto>> GetUserPrintJobs(string username) public async Task <ActionResult <PrinterDto> > AddPrinter(PrinterDto printer) { // var sourceUserId = User.GetUserId(); // var sourceUser = await this.unitOfWork.PrinterRepository.GetUserByIdPrintJobAsync(sourceUserId); // var sourceUser = await this.unitOfWork.UserRepository.GetUserByIdPrintJobAsync(sourceUserId); // var sourceUser = await this.unitOfWork.UserRepository.GetUserByUsernamePrintJobAsync(username); var addPrinter = new Printer { Id = printer.Id, PrinterName = printer.PrinterName, URL = printer.URL, Port = printer.port, SshUsername = printer.SshUsername, SshPassword = printer.SshPassword, SshHostname = printer.SshHostname, SshPublicKey = printer.SshPublicKey }; // Add a printer // var addPrinter2 = new Printer{ // Id = 1, // PrinterName = "Test", // URL = "None", // port = 631, // SshUsername = "******", // SshPassword = "******", // SshHostname = "localhost", // SshPublicKey = "none" // }; this.context.Printers.Add(addPrinter); // .Printers.Add(printer); // Just tracking in EF // await this.context.SaveChangesAsync(); // Saves changes to Entity Framework if (await unitOfWork.Complete()) { return(mapper.Map <PrinterDto>(addPrinter)); // return CreatedAtRoute("GetPrinters", mapper.Map<PrinterDto>(addPrinter)); // Now we're return the route to get the photos and the photo object //return CreatedAtRoute("GetUser", mapper.Map<PhotoDto>(photo)); //return CreatedAtRoute("GetUser", new {username = user.UserName}, mapper.Map<PhotoDto>(photo)); // return CreatedAtRoute("GetPrinters", new {}, mapper.Map<PrinterDto>(addPrinter)); // return CreatedAtRoute("GetPrinters", mapper.Map<PrinterDto>(addPrinter)); } return(BadRequest("Problem adding printer")); }
public async Task <ActionResponse <PrinterDto> > Update(PrinterDto entityDto) { try { var entityToUpdate = mapper.Map <PrinterDto, Printer>(entityDto); unitOfWork.GetGenericRepository <Printer>().Update(entityToUpdate); unitOfWork.Save(); return(await ActionResponse <PrinterDto> .ReturnSuccess(mapper.Map <Printer, PrinterDto>(entityToUpdate))); } catch (Exception) { return(await ActionResponse <PrinterDto> .ReturnError("Greška prilikom ažuriranja printera.")); } }
public async Task <ActionResponse <PrinterDto> > Update([FromBody] PrinterDto entityDto) { return(await printerService.Update(entityDto)); }