/// <summary> /// Post the specified request. /// </summary> /// <param name="request">Request.</param> public object Post(CreateSerie request) { WebSeries result; var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); try { context.Open(); Collection serie = new Collection(context); serie = (Terradue.Tep.Collection)request.ToEntity(context, serie); serie.Store(); serie.GrantPermissionsToAll(); Activity activity = new Activity(context, serie, EntityOperationType.Create); activity.Store(); context.LogInfo(this, string.Format("/data/collection POST Id='{0}'", serie.Id)); result = new WebSeries(serie); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public ActionResult Create(CreateSerie cs) { if (this.ModelState.IsValid) { try { Serie s = new Serie(); s.Annee = cs.Annee; s.Desc = cs.Desc; s.GuideParental = cs.GuideParental; s.GuideParentalId = cs.GuideParentalId; s.NbrEpisodes = cs.NbrEpisodes; s.Nom = cs.Nom; s.Studio = cs.Studio; s.StudioId = cs.StudioId; this.database.Serie.Add(s); this.database.SaveChanges(); if (cs.Cover != null && cs.Cover.ContentLength > 0) { cs.Cover.SaveAs(this.Server.MapPath(s.CoverPath)); } else { System.IO.File.Copy(this.Server.MapPath("/Content/Images/Serie/defaultcover.jpg"), this.Server.MapPath(s.CoverPath)); } return(this.RedirectToAction("Index")); } catch (Exception e) { this.ModelState.AddModelError("", e.Message); } } return(this.View(new CreateSerie())); }