public static bool EditPaint(PaintDTO order) { //List<ProductDTO> ProductsList = new List<ProductDTO>(); using (SqlConnection conn = new SqlConnection(cs)) { SqlCommand cmd = new SqlCommand("sp_update_kraska", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@id", order.Id); cmd.Parameters.AddWithValue("@name", order.Name); cmd.Parameters.AddWithValue("@desc", order.Description); cmd.Parameters.AddWithValue("@appl_area", order.Application_Area); cmd.Parameters.AddWithValue("@price", order.Price); cmd.Parameters.AddWithValue("@color", order.Color); cmd.Parameters.AddWithValue("@volume", order.Volume); cmd.Parameters.AddWithValue("@country", order.Country); cmd.Parameters.AddWithValue("@man", order.Manufacturer); cmd.Parameters.AddWithValue("@type", order.Type); cmd.Parameters.AddWithValue("@discount", order.Discount); conn.Open(); //dt.Load(cmd.ExecuteReader()); cmd.ExecuteNonQuery(); return(true); } }
public bool EditKraska(PaintDTO paint) { bool isAdded = false; isAdded = DataProvider.EditPaint(paint); return(isAdded); }
public async Task <IActionResult> PutPaint(int id, PaintDTO paintdto) { if (id != paintdto.Id) { return(BadRequest()); } var updatedPaintdto = await _paint.Update(paintdto, GetUserEmail()); return(Ok(updatedPaintdto)); }
// GetAPaint public async Task <PaintDTO> GetPaint(int id) { Paint paint = await _context.Paints.FindAsync(id); PaintDTO paintdto = new PaintDTO() { Id = id, ColorName = paint.ColorName, ProductNumber = paint.ProductNumber, Manufacturer = paint.Manufacturer }; return(paintdto); }
// ================== TODO =========================== // CreateAPaint public async Task <PaintDTO> Create(PaintDTO paintdto) { Paint paint = new Paint() { ColorName = paintdto.ColorName, ProductNumber = paintdto.ProductNumber, Manufacturer = paintdto.Manufacturer }; _context.Entry(paint).State = EntityState.Added; await _context.SaveChangesAsync(); return(paintdto); }
// GetAPaint /// <summary> /// Gets a singular paint /// </summary> /// <param name="id">integer for the id </param> /// <param name="email"> users email </param> /// <returns> a singular paintdto object </returns> public async Task <PaintDTO> GetPaint(int id, string email) { Paint paint = await _context.Paints.Where(x => x.Email == email) .FirstOrDefaultAsync(x => x.Id == id); PaintDTO paintdto = new PaintDTO() { Id = id, ColorName = paint.ColorName, ProductNumber = paint.ProductNumber, Manufacturer = paint.Manufacturer }; return(paintdto); }
// UpdateAPaint /// <summary> /// Updates a paint and saves it into the db /// </summary> /// <param name="paintdto"> dto for paint</param> /// <param name="email">users email</param> /// <returns> paintdto object</returns> public async Task <PaintDTO> Update(PaintDTO paintdto, string email) { Paint paint = new Paint() { Id = paintdto.Id, ColorName = paintdto.ColorName, ProductNumber = paintdto.ProductNumber, Manufacturer = paintdto.Manufacturer, Email = email }; _context.Entry(paint).State = EntityState.Modified; await _context.SaveChangesAsync(); return(paintdto); }
public async void CanCreateANewPaint() { var testEmail = "*****@*****.**"; var paint = new PaintDTO { ColorName = "Nulin Oil", Manufacturer = "Games Workshop", ProductNumber = "123" }; var service = BuildService(); var saved = await service.Create(paint, testEmail); Assert.NotNull(saved); Assert.Equal(paint.ColorName, saved.ColorName); Assert.Equal(paint.Manufacturer, saved.Manufacturer); Assert.Equal(paint.ProductNumber, saved.ProductNumber); }
public async void CanUpdateAPaint() { var testEmail = "*****@*****.**"; var service = BuildService(); var paint = new PaintDTO { Id = 1, ColorName = "Hot Orange", Manufacturer = "Citadel", ProductNumber = "72.063" }; await service.Update(paint, testEmail); var returnFromMethod = await service.GetPaint(1, testEmail); Assert.NotNull(returnFromMethod); Assert.Equal(paint.Id, returnFromMethod.Id); Assert.Equal(paint.ColorName, returnFromMethod.ColorName); Assert.Equal(paint.Manufacturer, returnFromMethod.Manufacturer); Assert.Equal(paint.ProductNumber, returnFromMethod.ProductNumber); }
public bool CreateKraska([FromForm] PaintDTO paint) { bool isAdded = false; isAdded = DataProvider.AddPaint(paint, out var id); string path = @"imgs\kraski\" + id; Directory.CreateDirectory(path); if (paint.Img1?.Length > 0) { using (var ms = new MemoryStream()) { paint.Img1.CopyTo(ms); var fileBytes = ms.ToArray(); string s = Convert.ToBase64String(fileBytes); // act on the Base64 data ISupportedImageFormat format = new JpegFormat { Quality = 10 }; using (MemoryStream inStream = new MemoryStream(fileBytes)) using (MemoryStream outStream = new MemoryStream()) { using (ImageFactory imageFactory = new ImageFactory(preserveExifData: false)) { var maxSize = new Size(200, 50); var r = new ResizeLayer(maxSize); r.MaxSize = maxSize; imageFactory.Load(inStream) .Resize(r) .Format(format) .Save(outStream); } using (System.Drawing.Image image = System.Drawing.Image.FromStream(outStream)) { var filePath = path + @"\11.jpg"; image.Save(filePath, ImageFormat.Jpeg); } } } //using (var fileStream = new FileStream(filePath, FileMode.Create)) //{ // paint.Img1.CopyTo(fileStream); //} } if (paint.Img2?.Length > 0) { using (var ms = new MemoryStream()) { paint.Img1.CopyTo(ms); var fileBytes = ms.ToArray(); string s = Convert.ToBase64String(fileBytes); // act on the Base64 data ISupportedImageFormat format = new JpegFormat { Quality = 50 }; using (MemoryStream inStream = new MemoryStream(fileBytes)) using (MemoryStream outStream = new MemoryStream()) { using (ImageFactory imageFactory = new ImageFactory(preserveExifData: false)) { var maxSize = new Size(10, 10); var r = new ResizeLayer(maxSize); r.MaxSize = maxSize; imageFactory.Load(inStream) .Resize(r) .Format(format) .Save(outStream); } using (System.Drawing.Image image = System.Drawing.Image.FromStream(outStream)) { var filePath = path + @"\2.jpg"; image.Save(filePath, ImageFormat.Jpeg); } } } //var filePath = path + @"\2.jpg"; //using (var fileStream = new FileStream(filePath, FileMode.Create)) //{ // paint.Img2.CopyTo(fileStream); //} } if (paint.Img3?.Length > 0) { var filePath = path + @"\3.jpg"; using (var fileStream = new FileStream(filePath, FileMode.Create)) { paint.Img3.CopyTo(fileStream); } } return(isAdded); }
public static bool AddPaint(PaintDTO order, out int id) { int cnt = 0; if (order.Img1 != null) { cnt++; } if (order.Img2 != null) { cnt++; } if (order.Img3 != null) { cnt++; } //DataTable dt = new DataTable(); //List<ProductDTO> ProductsList = new List<ProductDTO>(); using (SqlConnection conn = new SqlConnection(cs)) { SqlCommand cmd = new SqlCommand("sp_insert_kraska", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@name", order.Name); cmd.Parameters.AddWithValue("@desc", order.Description); cmd.Parameters.AddWithValue("@appl_area", order.Application_Area); cmd.Parameters.AddWithValue("@price", order.Price); cmd.Parameters.AddWithValue("@color", order.Color); cmd.Parameters.AddWithValue("@volume", order.Volume); cmd.Parameters.AddWithValue("@country", order.Country); cmd.Parameters.AddWithValue("@man", order.Manufacturer); cmd.Parameters.AddWithValue("@type", order.Type); cmd.Parameters.AddWithValue("@discount", order.Discount); cmd.Parameters.AddWithValue("@imgscount", cnt); SqlParameter outParameter = new SqlParameter("@id", SqlDbType.Int); outParameter.Direction = ParameterDirection.Output; cmd.Parameters.Add(outParameter); //cmd.Parameters.Add("@items", SqlDbType.Structured); //cmd.Parameters.Add("@items", SqlDbType.Structured); //cmd.Parameters.Add("@items", SqlDbType.Structured); //cmd.Parameters["@items"].Value = order.Items; //cmd.Parameters.AddWithValue("@items", order.Items); conn.Open(); //dt.Load(cmd.ExecuteReader()); cmd.ExecuteNonQuery(); //foreach (DataRow dr in dt.Rows) //{ // ProductsList.Add(dr.ConvertToProductDTO()); //} id = Convert.ToInt32(outParameter.Value); return(true); } }
public async Task <ActionResult <Paint> > PostPaint(PaintDTO paintdto) { await _paint.Create(paintdto, GetUserEmail()); return(CreatedAtAction("GetPaint", new { id = paintdto.Id }, paintdto)); }