public ActionResult <string> AddAddedPart([FromBody] addedPartDTO addedPartDTO) { try { BUser user = _bUserRepository.GetByEmail(addedPartDTO.email); Part part = _partRepository.GetById(addedPartDTO.partId); if (user != null && part != null) { _addedPartRepository.AddAddedPart(new AddedPart { Name = addedPartDTO.name, Brand = addedPartDTO.brand, Price = addedPartDTO.price, BUser = user, Part = part, Link = addedPartDTO.link }); _addedPartRepository.SaveChanges(); AddedPart addedPart = _addedPartRepository.GetMostRecentByPartIdAndEmail(addedPartDTO.partId, addedPartDTO.email); addedPartDTO.id = addedPart.Id; return(Ok(addedPartDTO)); } return(NotFound("This email address isn't know")); } catch (Exception e) { return(NotFound(e.Message)); } }
public void AddAddedPart(AddedPart part) { if (part != null) { _AddedParts.Add(part); } }
public ActionResult <String> AddImage(int id) { IFormFile files = Request.Form.Files[0]; AddedPart part = _addedPartRepository.GetById(id); if (files != null) { MemoryStream ms = new MemoryStream(); files.CopyTo(ms); Image image = new Image { ImageData = ms.ToArray(), PartId = part.Id }; _imageRepository.addImage(image); _imageRepository.saveChanges(); return(Ok()); } return(BadRequest()); }