Exemple #1
0
        public async Task <int> AddPhotoAsync(AdPhotos adPhoto)
        {
            await _db.AddAsync(adPhoto);

            await _db.SaveChangesAsync();

            return(adPhoto.AdPhotosId);
        }
Exemple #2
0
        public ActionResult Post([FromForm] AdsModel std)
        {
            var images = std.Images;


            int nextAdId = db.Ad.Max(a => a.Id) + 1;

            Ad ad = new Ad();

            ad.Name          = std.name;
            ad.CategoryId    = std.categoryId;
            ad.Price         = std.price;
            ad.UserId        = std.userId;
            ad.Description   = std.description;
            ad.ConditionId   = std.conditionId;
            ad.TypeId        = std.typeId;
            ad.Communication = std.communication;
            db.Add(ad);

            foreach (var image in images)
            {
                String imageName = image.FileName;

                if (imageName.Length > 0)
                {
                    using (var fileStream = new FileStream(imageName, FileMode.Create))
                    {
                        image.CopyTo(fileStream);
                        var ms = new MemoryStream();
                        fileStream.CopyTo(ms);

                        AdPhotos adPhotos = new AdPhotos();
                        adPhotos.Photo = imageName;
                        adPhotos.AdId  = nextAdId;

                        db.AdPhotos.Add(adPhotos);
                        db.SaveChanges();
                    }
                }
            }

            return(Ok(new { status = true, message = "Ad posted successfully!" }));
        }
Exemple #3
0
 public async Task RemovePhoto(AdPhotos adPhoto)
 {
     _db.Remove(adPhoto);
     await _db.SaveChangesAsync();
 }