Example #1
0
 public AdvertVm(Advert advert, int page)
 {
     AdvertID = advert.AdvertID;
     Title = advert.Title;
     Description = advert.Description;
     ImagePath = advert.ImagePath;
     UserId = advert.UserId;
     UserName = advert.User.Login;
     PageNumber = page;
 }
Example #2
0
        public void AddAdvert(AddAdvert _advert, string _indname)
        {
            var user = db.Users.FirstOrDefault(b => b.Login == _indname);
             string appData = AppDomain.CurrentDomain.BaseDirectory + "Content/Images";
             string randomFileName = Path.GetRandomFileName();
             string files = Path.Combine(appData, randomFileName + Path.GetExtension(_advert.Image.FileName));
             _advert.Image.SaveAs(files);

              var item = new Advert
              {
                   Date = DateTime.Now,
                   Description = _advert.Description,
                   ImagePath = "\\Content\\Images\\" + randomFileName + Path.GetExtension(_advert.Image.FileName),
                   Title = _advert.Title,
                   UserId = user.Id,
              };
            db.Adverts.Add(item);
            db.SaveChanges();
        }
Example #3
0
 public void DeleteAdvert(Advert _advert)
 {
     System.IO.File.Delete(AppDomain.CurrentDomain.BaseDirectory + _advert.ImagePath);
     db.Adverts.Remove(_advert);
     db.SaveChanges();
 }