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; }
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(); }
public void DeleteAdvert(Advert _advert) { System.IO.File.Delete(AppDomain.CurrentDomain.BaseDirectory + _advert.ImagePath); db.Adverts.Remove(_advert); db.SaveChanges(); }