示例#1
0
        public int AddFabric(Fabric fabric, IFormFile image)
        {
            try
            {
                var dir = _env.ContentRootPath;

                string pathToFabricPictures = "/Images/fabric_pictures";

                string fullPath = dir + pathToFabricPictures;

                if (!Directory.Exists(fullPath))
                {
                    Directory.CreateDirectory(fullPath);
                }

                int fileSuffix = 1;

                string fullFileName = "fabric_picture_" + fileSuffix + ".png";

                bool exists = System.IO.File.Exists(Path.Combine(fullPath, fullFileName));

                while (exists)
                {
                    fileSuffix++;
                    fullFileName = "fabric_picture_" + fileSuffix + ".png";
                    exists       = System.IO.File.Exists(Path.Combine(fullPath, fullFileName));
                }

                using (var fileStream = new FileStream(Path.Combine(fullPath, fullFileName), FileMode.Create, FileAccess.Write))
                {
                    image.CopyTo(fileStream);

                    Fabric  fabricToCreate = new Fabric();
                    Picture pictureExists  = db.Picture
                                             .Where(p => p.PictureName == fullFileName)
                                             .FirstOrDefault();

                    if (pictureExists == null)
                    {
                        Picture picture = new Picture(0, fullFileName);
                        db.Picture.Add(picture);
                        fabric.PictureId = picture.PictureId;
                        fabric.Picture   = picture;
                    }
                    else
                    {
                        fabric.PictureId = pictureExists.PictureId;
                        fabric.Picture   = pictureExists;
                    }
                    db.Fabric.Add(fabric);
                    db.SaveChanges();
                    return(1);
                }
            }
            catch
            {
                throw;
            }
        }
 public int AddRating(Rating rating)
 {
     try
     {
         db.Rating.Add(rating);
         db.SaveChanges();
         return(1);
     }
     catch
     {
         throw;
     }
 }
示例#3
0
 public int AddPicture(Picture picture)
 {
     try
     {
         db.Picture.Add(picture);
         db.SaveChanges();
         return(1);
     }
     catch
     {
         throw;
     }
 }
示例#4
0
 public int AddCarpentryService(CarpentryService carpentryService)
 {
     try
     {
         db.CarpentryService.Add(carpentryService);
         db.SaveChanges();
         return(1);
     }
     catch
     {
         throw;
     }
 }
示例#5
0
 public int AddFabricType(FabricType fabricType)
 {
     try
     {
         db.FabricType.Add(fabricType);
         db.SaveChanges();
         return(1);
     }
     catch
     {
         throw;
     }
 }