public IHttpActionResult PutUlotka(int id, Ulotka ulotka) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != ulotka.Id) { return(BadRequest()); } db.Entry(ulotka).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!UlotkaExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult DeleteConfirmed(int id) { Ulotka ulotka = db.Ulotki.Find(id); db.Ulotki.Remove(ulotka); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,ApplicationUserId,Title,Description,FileSetType,StartDate,EndDate,PublishDate,SklepId")] Ulotka ulotka) { if (ModelState.IsValid) { db.Entry(ulotka).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.SklepId = new SelectList(db.Sklepy, "Id", "Id", ulotka.SklepId); return(View(ulotka)); }
public IHttpActionResult GetUlotka(int id) { Ulotka ulotka = db.Ulotki.Find(id); if (ulotka == null) { return(NotFound()); } return(Ok(ulotka)); }
public IHttpActionResult PostUlotka(Ulotka ulotka) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Ulotki.Add(ulotka); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = ulotka.Id }, ulotka)); }
public ActionResult Create([Bind(Include = "Title,FileSetType,urls,Description,StartDate,EndDate,SklepId")] Ulotka ulotka) { ulotka.ApplicationUserId = User.Identity.GetUserId(); ulotka.PublishDate = DateTime.Now; //ulotka.FileSetType ModelState.Clear(); var urls = ulotka.urls.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (TryValidateModel(ulotka) && ServerTools.TempFolderContains(urls)) { try { if (ulotka.FileSetType == FileSetType.Pdf) { string filePath = Path.Combine(ServerTools.TempFolderPath, urls.First()); ulotka.urls = ServerTools.ConvertPdfToImages(filePath); System.IO.File.Delete(filePath); } else { string destinationUrlList = string.Empty; foreach (var item in urls) { //todo better naming /sklep/ulotka123 string sourcePath = Path.Combine(ServerTools.TempFolderPath, item); string folder = ulotka.FileSetType == FileSetType.Pdf ? "Data/Pdf" : "Data/Images"; string destinationFilePath = Path.Combine(ServerTools.MediaFolderPath(folder), item); System.IO.File.Move(sourcePath, destinationFilePath); destinationUrlList += ServerTools.RelativePath(destinationFilePath) + ";"; } ulotka.urls = destinationUrlList; } db.Ulotki.Add(ulotka); db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception) { string key = "urls"; if (ModelState.ContainsKey(key)) { ModelState.Remove(key); } ModelState.AddModelError(key, "Wybrane pliki nie są wspierane."); } } ViewBag.SklepId = new SelectList(db.Sklepy, "Id", "Id", ulotka.SklepId); return(View(ulotka)); }
// GET: Ulotki/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Ulotka ulotka = db.Ulotki.Find(id); if (ulotka == null) { return(HttpNotFound()); } return(View(ulotka)); }
public IHttpActionResult DeleteUlotka(int id) { Ulotka ulotka = db.Ulotki.Find(id); if (ulotka == null) { return(NotFound()); } db.Ulotki.Remove(ulotka); db.SaveChanges(); return(Ok(ulotka)); }
// GET: Ulotki/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Ulotka ulotka = db.Ulotki.Find(id); if (ulotka == null) { return(HttpNotFound()); } ViewBag.SklepId = new SelectList(db.Sklepy, "Id", "Id", ulotka.SklepId); return(View(ulotka)); }