public void CreateCupcake(Cupcake cupcake)
 {
     if (cupcake.PhotoAvatar != null && cupcake.PhotoAvatar.Length > 0)
     {
         cupcake.ImageMimeType = cupcake.PhotoAvatar.ContentType;
         cupcake.ImageName     = Path.GetFileName(cupcake.PhotoAvatar.FileName);
         using (var ms = new MemoryStream())
         {
             cupcake.PhotoAvatar.CopyTo(ms);
             cupcake.PhotoFile = ms.ToArray();
         }
         _context.Add(cupcake);
         _context.SaveChanges();
     }
 }
Example #2
0
 public void CreateCupcake(Cupcake cupcake)
 {
     if (cupcake.PhotoAvatar?.Length > 0)
     {
         cupcake.ImageMimeType = cupcake.PhotoAvatar.ContentType;
         cupcake.ImageName     = cupcake.PhotoAvatar.FileName;
         using (var memoryStream = new MemoryStream())
         {
             cupcake.PhotoAvatar.CopyTo(memoryStream);
             cupcake.PhotoFile = memoryStream.ToArray();
         }
     }
     _context.Add(cupcake);
     _context.SaveChanges();
 }
Example #3
0
 public void CreateCupcake(Cupcake cupcake)
 {
     if (cupcake.PhotoAvatar is not null)
     {
         if (cupcake.PhotoAvatar.Length > 0)
         {
             cupcake.ImageMimeType         = cupcake.PhotoAvatar.ContentType;
             cupcake.ImageName             = Path.GetFileName(cupcake.PhotoAvatar.FileName);
             using MemoryStream _ctxMemory = new();
             cupcake.PhotoAvatar.CopyTo(_ctxMemory);
             cupcake.PhotoFile = _ctxMemory.ToArray();
         }
     }
     _ = _context.Add(cupcake);
     _ = _context.SaveChanges();
 }