public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } using (var context = new AF_Context()) { Festival fes = context.Festivals.Find(id); if (fes == null) { return(HttpNotFound()); } var newFestivalDto = new FestivalDTO() { FestivalId = fes.FestivalId, Year = fes.Year, BeginningDate = fes.BeginningDate, EndDate = fes.EndDate, }; //ViewBag.EditedBy = new SelectList(db.Users, "UserId", "Login", play.EditedBy); //ViewBag.FestivalId = new SelectList(db.Festivals, "FestivalId", "FestivalId", play.FestivalId); return(View(newFestivalDto)); } }
public async Task <IHttpActionResult> PostFestival([FromBody] Festival festival) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Festivals.Add(festival); await db.SaveChangesAsync(); //db.Entry(artiste).Reference(x => x.Programmations).Load(); var dto = new FestivalDTO() { Id = festival.Id, Description = festival.Description, DateFin = festival.DateFin, Nom = festival.Nom, DateDebut = festival.DateDebut, Lieu = festival.Lieu, CodePostal = festival.CodePostal, UserId = festival.UserId, Prix = festival.Prix, IsInscription = festival.IsInscription, IsPublication = festival.IsPublication }; return(CreatedAtRoute("DefaultApi", new { id = festival.Id }, dto)); }
public ActionResult Edit([Bind(Include = "FestivalId,Year,BeginningDate,EndDate")] FestivalDTO updateData) { if (ModelState.IsValid) { var updateDataFull = new Festival() { FestivalId = updateData.FestivalId, Year = updateData.Year, BeginningDate = updateData.BeginningDate, EndDate = updateData.EndDate, EditedBy = 1,//GetUserId(), EditDate = DateTime.Now }; using (var context = new AF_Context()) { Festival fes = context.Festivals.Find(updateData.FestivalId); context.Entry(fes).CurrentValues.SetValues(updateDataFull); context.SaveChanges(); return(RedirectToAction("Index")); } } //ViewBag.EditedBy = new SelectList(db.Users, "UserId", "Login", play.EditedBy); //ViewBag.FestivalId = new SelectList(db.Festivals, "FestivalId", "FestivalId", play.FestivalId); return(View(updateData)); }
public ListResponse <FestivalDTO> GetFestivalsPaged(int pageNr, int pageAmount) { using (var context = new AF_Context()) { try { var skip = pageAmount * (pageNr - 1); List <FestivalDTO> tmp = new List <FestivalDTO>(); foreach (Festival fe in (from f in context.Festivals.Include(u => u.Editor) select f).Skip(skip).Take(pageAmount)) { var newFestivalDto = new FestivalDTO() { FestivalId = fe.FestivalId, Year = fe.Year, BeginningDate = fe.BeginningDate, EndDate = fe.EndDate }; tmp.Add(newFestivalDto); } return(new ListResponse <FestivalDTO>(tmp)); } catch (Exception ex) { throw; } return(null); } }
public SingleItemResponse <FestivalDTO> UpdateFestival(FestivalDTO updateData) { var updateDataFull = new Festival() { FestivalId = updateData.FestivalId, Year = updateData.Year, BeginningDate = updateData.BeginningDate, EndDate = updateData.EndDate, EditedBy = GetUserId(), EditDate = DateTime.Now }; using (var context = new AF_Context()) { try { Festival fes = context.Festivals.First(f => f.FestivalId == updateData.FestivalId); context.Entry(fes).CurrentValues.SetValues(updateDataFull); context.SaveChanges(); int id = updateData.FestivalId; return(GetFestival(id)); } catch (Exception ex) { throw; } } }
public SingleItemResponse <FestivalDTO> AddFestival(FestivalDTO newFestival) { var newFestivalFull = new Festival() { Year = newFestival.Year, BeginningDate = newFestival.BeginningDate, EndDate = newFestival.EndDate, EditedBy = GetUserId(), EditDate = DateTime.Now }; using (var context = new AF_Context()) { try { context.Festivals.Add(newFestivalFull); context.SaveChanges(); int id = newFestivalFull.FestivalId; return(GetFestival(id)); } catch (Exception ex) { throw; } } }
public IHttpActionResult Create(FestivalDTO festivalDTO) { if (ModelState.IsValid) { try { var festival = Mapper.Map <FestivalDTO, Festival>(festivalDTO); festivalService.Create(festival); return(Ok("Festival succesfully created")); } catch (Exception ex) { return(BadRequest("Something went wrong.")); } } else { return(BadRequest(ModelState)); } }
public SingleItemResponse <FestivalDTO> GetFestival(int id) { using (var context = new AF_Context()) { try { Festival fes = context.Festivals.First(f => f.FestivalId == id); var newFestivalDto = new FestivalDTO() { FestivalId = fes.FestivalId, Year = fes.Year, BeginningDate = fes.BeginningDate, EndDate = fes.EndDate, }; return(new SingleItemResponse <FestivalDTO>(newFestivalDto)); } catch (Exception ex) { throw; } } }
// GET: /Festival/ public ActionResult Index() { //var festivals = db.Festivals.Include(f => f.Editor); //return View(festivals.ToList()); using (var context = new AF_Context()) { var skip = 0;//pageAmount * (pageNr - 1); int pageAmount = 100; List <FestivalDTO> tmp = new List <FestivalDTO>(); foreach (Festival fe in (from f in context.Festivals//.Include(u => u.Editor) select f).OrderBy(f => f.Year).Skip(skip).Take(pageAmount)) { var newFestivalDto = new FestivalDTO() { FestivalId = fe.FestivalId, Year = fe.Year, BeginningDate = fe.BeginningDate, EndDate = fe.EndDate }; tmp.Add(newFestivalDto); } return(View(tmp)); } }
// GET: /Festival/ public ActionResult Index() { //var festivals = db.Festivals.Include(f => f.Editor); //return View(festivals.ToList()); using (var context = new AF_Context()) { var skip = 0;//pageAmount * (pageNr - 1); int pageAmount = 100; List<FestivalDTO> tmp = new List<FestivalDTO>(); foreach (Festival fe in (from f in context.Festivals//.Include(u => u.Editor) select f).OrderBy(f => f.Year).Skip(skip).Take(pageAmount)) { var newFestivalDto = new FestivalDTO() { FestivalId = fe.FestivalId, Year = fe.Year, BeginningDate = fe.BeginningDate, EndDate = fe.EndDate }; tmp.Add(newFestivalDto); } return View(tmp); } }
public ActionResult Edit(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } using (var context = new AF_Context()) { Festival fes = context.Festivals.Find(id); if (fes == null) { return HttpNotFound(); } var newFestivalDto = new FestivalDTO() { FestivalId = fes.FestivalId, Year = fes.Year, BeginningDate = fes.BeginningDate, EndDate = fes.EndDate, }; //ViewBag.EditedBy = new SelectList(db.Users, "UserId", "Login", play.EditedBy); //ViewBag.FestivalId = new SelectList(db.Festivals, "FestivalId", "FestivalId", play.FestivalId); return View(newFestivalDto); } }
public ListResponse<FestivalDTO> GetFestivalsPaged(int pageNr, int pageAmount) { using (var context = new AF_Context()) { try { var skip = pageAmount*(pageNr - 1); List<FestivalDTO> tmp = new List<FestivalDTO>(); foreach (Festival fe in (from f in context.Festivals.Include(u => u.Editor) select f).Skip(skip).Take(pageAmount)) { var newFestivalDto = new FestivalDTO() { FestivalId = fe.FestivalId, Year = fe.Year, BeginningDate = fe.BeginningDate, EndDate = fe.EndDate }; tmp.Add(newFestivalDto); } return (new ListResponse<FestivalDTO>(tmp)); } catch (Exception ex) { throw; } return null; } }
public SingleItemResponse<FestivalDTO> GetFestival(int id) { using (var context = new AF_Context()) { try { Festival fes = context.Festivals.First(f => f.FestivalId == id); var newFestivalDto = new FestivalDTO() { FestivalId = fes.FestivalId, Year = fes.Year, BeginningDate = fes.BeginningDate, EndDate = fes.EndDate, }; return (new SingleItemResponse<FestivalDTO>(newFestivalDto)); } catch (Exception ex) { throw; } } }
public SingleItemResponse<FestivalDTO> UpdateFestival(FestivalDTO updateData) { var updateDataFull = new Festival() { FestivalId = updateData.FestivalId, Year = updateData.Year, BeginningDate = updateData.BeginningDate, EndDate = updateData.EndDate, EditedBy = GetUserId(), EditDate = DateTime.Now }; using (var context = new AF_Context()) { try { Festival fes = context.Festivals.First(f => f.FestivalId == updateData.FestivalId); context.Entry(fes).CurrentValues.SetValues(updateDataFull); context.SaveChanges(); int id = updateData.FestivalId; return GetFestival(id); } catch (Exception ex) { throw; } } }
public SingleItemResponse<FestivalDTO> AddFestival(FestivalDTO newFestival) { var newFestivalFull = new Festival() { Year = newFestival.Year, BeginningDate = newFestival.BeginningDate, EndDate = newFestival.EndDate, EditedBy = GetUserId(), EditDate = DateTime.Now }; using (var context = new AF_Context()) { try { context.Festivals.Add(newFestivalFull); context.SaveChanges(); int id = newFestivalFull.FestivalId; return GetFestival(id); } catch (Exception ex) { throw; } } }