protected void Approve(object sender, EventArgs e) { EditedAd.Approved = true; EditedAd.Status = ReviewStatus.Reviewed; context.SaveChanges(); Response.Redirect("/Admin/Admin.aspx?AdQUery=unapproved"); }
public ActionResult CreateAd(Ad model, HttpPostedFileBase image) { if (ModelState.IsValid) { if (image != null) { byte[] temp = null; using (BinaryReader reader = new BinaryReader(image.InputStream)) { temp = reader.ReadBytes(image.ContentLength); } model.Photo = temp; } else { model.Photo = null; } model.ID = Guid.NewGuid(); model.AuthorID = new Guid(User.Identity.Name); model.DateCreated = DateTime.Now.ToString(); db.Ads.Add(model); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); }
public ActionResult DeleteMyAd(int?id) { Ad toDelete = db.Ads.Find(id); db.Ads.Remove(toDelete); db.SaveChanges(); return(RedirectToAction("ViewMyProfile")); }
public Ad DeleteAd(int Id) { Ad dbEntry = adcontext.Ads.Find(Id); if (dbEntry != null) { adcontext.Ads.Remove(dbEntry); adcontext.SaveChanges(); } return(dbEntry); }
public ActionResult Create([Bind(Include = "AdminMessageID,Title,Content")] AdminMessage adminMessage) { if (ModelState.IsValid) { db.AdminMessages.Add(adminMessage); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(adminMessage)); }
public ActionResult Create([Bind(Include = "ForbiddenWordID,Name")] ForbiddenWord forbiddenWord) { if (ModelState.IsValid) { db.ForbiddenWords.Add(forbiddenWord); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(forbiddenWord)); }
public ActionResult Create([Bind(Include = "CategoryID,Name,ParentcategoryID")] Category category) { if (ModelState.IsValid) { db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Create([Bind(Include = "AttributeID,Type,Name,Value,CategoryID")] Ads.Models.Attribute attribute) { if (ModelState.IsValid) { db.Attributes.Add(attribute); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "Name", attribute.CategoryID); return(View(attribute)); }
public ActionResult Update(Ad ad) { if (ad != null) { if (ModelState.IsValid) { db.Entry(ad).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } } return(View(ad)); }
public (int Id, bool Success) Add(Ad model) { _context.Ads.Add(model); try { _context.SaveChanges(); return(model.Id, true); } catch (DbUpdateException) { return(-1, false); } }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new AdContext( serviceProvider.GetRequiredService <DbContextOptions <AdContext> >())) { // Look for any advertisement if (context.Categories.Any()) { return; // DB has been seeded } context.Categories.AddRange( new Category { Name = "Consumering" }, new Category { Name = "Dienst" }, new Category { Name = "Product" }, new Category { Name = "Politiek" } ); context.SaveChanges(); } }
protected void Update(object sender, EventArgs e) { EditedAd.Text = AdTextUpdate.Text; EditedAd.Approved = false; EditedAd.Status = ReviewStatus.WaitingForReview; context.SaveChanges(); DataBind(); }
protected void Publish() { if (PublishedAd.TokenValue != null)//Already published { return; } PublishedAd.TokenValue = TokenService.Generate(); context.SaveChanges(); }
protected void Page_Load(object sender, EventArgs e) { context = new AdContext(); EditedAd = context.Ads.Find(Int32.Parse(Request.QueryString["id"])); if (!IsPostBack) { EditedAd.Status = ReviewStatus.InReview; context.SaveChanges(); DataBind(); } }
private void SeedCategories(AdContext context) { for (int i = 1; i <= 10; i++) { var category = new Category() { Id = i, CategoryName = " Category Name" + i.ToString(), ParentId = i }; context.Set <Category>().AddOrUpdate(category); } context.SaveChanges(); }
private void SeedAdCategory(AdContext context) { for (int i = 1; i <= 10; i++) { var adcat = new AdCategory() { Id = i, AdId = i / 2 + 1, CategoryId = i / 2 + 2 }; context.Set <AdCategory>().AddOrUpdate(adcat); } context.SaveChanges(); }
protected void PostAd(object sender, EventArgs e) { AdContext context = new AdContext(); Ad ad = new Ad { Id = 1, Text = Neutralize(AdText.Text), CreatorUser = User.Identity.Name, Status = ReviewStatus.WaitingForReview, Approved = AutoApprove.Checked }; context.Ads.Add(ad); context.SaveChanges(); AdText.Text = ""; Message = "Ad Posted. An Approver will check and approve it soon!"; }
private void SeedAdvertisements(AdContext context) { var idUser = context.Set <User>().Where(u => u.UserName == "Admin").FirstOrDefault().Id; for (int i = 1; i <= 10; i++) { var ad = new Advertisement() { Id = i, UserID = idUser, Content = "Ad Content" + i.ToString(), Title = "Ad Title" + i.ToString(), DateOfAdd = DateTime.Now.AddDays(-i) }; context.Set <Advertisement>().AddOrUpdate(ad); } context.SaveChanges(); }
public static USerPsk GetPsk(string employeeId) { using (var context = new AdContext()) { var psk = context.USerPsks.FirstOrDefault(o => o.EmployeeId == employeeId); if (psk != null) { return(context.USerPsks.FirstOrDefault(o => o.EmployeeId == employeeId)); } { context.USerPsks.Add(new USerPsk { EmployeeId = employeeId, Psk = TimeSensitivePassCode.GeneratePresharedKey() }); context.SaveChanges(); return(context.USerPsks.FirstOrDefault(o => o.EmployeeId == employeeId)); } } }
public static void GenerateThumbnail( [QueueTrigger("thumbnailrequest")] BlobInformation blobInfo, [Blob("images/{BlobName}", FileAccess.Read)] Stream input, [Blob("images/{BlobNameWithoutExtension}_thumbnail.jpg")] CloudBlockBlob outputBlob) { using (Stream output = outputBlob.OpenWrite()) { ConvertImageToThumbnailJpg(input, output); outputBlob.Properties.ContentType = "image/jpeg"; } using (AdContext adContext = new AdContext()) { var ad = adContext.Ads.Find(blobInfo.AdId); if (ad == null) { throw new Exception(String.Format("Cannot create thumbnail for AdId {0}", blobInfo.AdId)); } ad.ThumbnailUrl = outputBlob.Uri.ToString(); adContext.SaveChanges(); } }
public ActionResult Create([Bind(Include = "AdID,Title,Content,DateOfInsert,CategoryID,UserID")] Ad ad, HttpPostedFileBase file, List <string> aaa) { // var query = db.Ads.Where(c => c.Name.ToLower() == ad.Name.ToLower()); //var query = db.Companies.Where(c => c.Name.Contains("A")).OrderBy(c => c.Name); //var queryFW = db.ForbiddenWords; int count = 0; var queryFW = from c in db.ForbiddenWords select c.Name; List <string> fWords = queryFW.ToList(); for (int i = 0; i < fWords.Count; i++) { if (ad.Content.Contains(fWords[i])) { count++; } } if (count != 0) { ModelState.AddModelError("", "Nie można dodać ogłoszenia, które zawiera słowa zakazane"); } //--------------------------------Dodawanie multimediow --------------------------- var originalDirectory = new DirectoryInfo(string.Format("{0}Images\\Uploads", Server.MapPath(@"\"))); var pathString1 = Path.Combine(originalDirectory.ToString(), "Ads"); var pathString2 = Path.Combine(originalDirectory.ToString(), "Ads" + ad.AdID.ToString()); var pathString3 = Path.Combine(originalDirectory.ToString(), "Ads" + ad.AdID.ToString() + "\\Thumbs"); var pathString4 = Path.Combine(originalDirectory.ToString(), "Ads" + ad.AdID.ToString() + "\\Galery"); var pathString5 = Path.Combine(originalDirectory.ToString(), "Ads" + ad.AdID.ToString() + "\\Galery\\Thumbs"); if (!Directory.Exists(pathString1)) { Directory.CreateDirectory(pathString1); } if (!Directory.Exists(pathString2)) { Directory.CreateDirectory(pathString2); } if (!Directory.Exists(pathString3)) { Directory.CreateDirectory(pathString3); } if (!Directory.Exists(pathString4)) { Directory.CreateDirectory(pathString4); } if (!Directory.Exists(pathString5)) { Directory.CreateDirectory(pathString5); } if (file != null && file.ContentLength > 0) { string ext = file.ContentType.ToLower(); if (ext != "image/jpg" && ext != "image/jpeg" && ext != "image/pjpeg" && ext != "image/gif" && ext != "image/png") { ModelState.AddModelError("", "Plik nie zostal załadowany - złe rozszerzenie"); return(View(ad)); } string imageName = file.FileName; ad.MediaPath = imageName; db.SaveChanges(); var path = string.Format("{0}\\{1}", pathString2, imageName); var path2 = string.Format("{0}\\{1}", pathString3, imageName); file.SaveAs(path); WebImage img = new WebImage(file.InputStream); img.Resize(200, 200); img.Save(path2); } //-------------------Koniec : dodawanie multimediow------------ var list = db.Attributes.Where(x => x.CategoryID == ad.CategoryID).ToList(); if (aaa != null) { ad.Content += "\n"; for (int i = 0; i < aaa.Count; i++) { ad.Content += "\n" + list[i].Name + ": " + aaa[i]; } } if (ModelState.IsValid) { ad.DateOfInsert = DateTime.Now; ad.UserID = Convert.ToInt16(Session["UserID"]); db.Ads.Add(ad); db.SaveChanges(); // return RedirectToAction("Create"); return(RedirectToAction("Showsubcategories", "Categories", new { id = ad.CategoryID })); } else { return(RedirectToAction("ForbiddenError")); } /* ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "Name", ad.CategoryID); * ViewBag.UserID = new SelectList(db.Users, "UserID", "Login", ad.UserID); * * return View(ad);*/ }