public IHttpActionResult PutApi(int id, Api api) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != api.ID) { return(BadRequest()); } db.Entry(api).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ApiExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> Register(RegisterBindingModel model) { HttpRequest httpRequest = HttpContext.Current.Request; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = new ApplicationUser() { UserName = model.Email, Email = model.Email }; IdentityResult result = await UserManager.CreateAsync(user, model.Password); if (!result.Succeeded) { return(GetErrorResult(result)); } if (result.Succeeded) { var currentUser = UserManager.FindByName(user.UserName); UserManager.AddToRole(currentUser.Id, model.Role); } var context = new NEWSEntities(); if (model.Role == "journalistes") { var j = new Journalistes(); var currentUser = UserManager.FindByName(user.UserName); j.Nom = httpRequest["Nom"]; j.Prenom = httpRequest["Prenom"]; j.User_id = currentUser.Id; context.Journalistes.Add(j); context.SaveChanges(); } else if (model.Role == "ChefRedaction") { var r = new RedacteurEnChef(); var currentUser = UserManager.FindByName(user.UserName); r.Nom = httpRequest["Nom"]; r.Prenom = httpRequest["Prenom"]; r.User_id = currentUser.Id; context.RedacteurEnChef.Add(r); context.SaveChanges(); } return(Ok()); }
public void Update(Post Instance) { using (var db = new NEWSEntities()) { try { var existItem = db.Posts.SingleOrDefault(d => d.ID == Instance.ID); existItem.Title = Instance.Title; existItem.ShortDescription = Instance.ShortDescription; existItem.LongDescription = Instance.LongDescription; existItem.MainImageUrl = Instance.MainImageUrl; existItem.CreateDate = Instance.CreateDate; existItem.Actived = Instance.Actived; existItem.ViewerCount = Instance.ViewerCount; existItem.IsGallery = Instance.IsGallery; existItem.AuthorID = Instance.AuthorID; existItem.CategoryID = Instance.CategoryID; existItem.PostGalleryID = Instance.PostGalleryID; db.SaveChanges(); } catch (Exception ex) { throw new AggregateException(ex); } } }
public void SetTagToPost(long postID, long tagID) { using (var db = new NEWSEntities()) { var post = db.Posts.SingleOrDefault(p => p.ID == postID); var tag = db.Tags.SingleOrDefault(t => t.ID == tagID); post.Tags.Add(tag); db.SaveChanges(); } }
public void SetGalleryToPost(long postGalleryID, IList <long> galleryID) { using (var db = new NEWSEntities()) { foreach (var item in galleryID) { var gallery = db.Galleries.SingleOrDefault(g => g.ID == item); gallery.PostGalleryID = postGalleryID; db.SaveChanges(); } } }
public IHttpActionResult PostArticle(Article article) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var context = new NEWSEntities()) { context.Article.Add(article); context.SaveChanges(); } return(CreatedAtRoute("DefaultApi", new { id = article.ID }, article)); }
public void Create(Category Instance) { using (var db = new NEWSEntities()) { try { db.Categories.Add(Instance); db.SaveChanges(); } catch (Exception ex) { throw new AggregateException(ex); } } }
public IHttpActionResult PostContact(Contact contact) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var context = new NEWSEntities()) { context.Contact.Add(contact); context.SaveChanges(); } return(CreatedAtRoute("DefaultApi", new { id = contact.Id }, contact)); }
public IHttpActionResult PostArticle(Commentaire commentaire) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var context = new NEWSEntities()) { context.Commentaire.Add(commentaire); context.SaveChanges(); } return(Ok()); //return CreatedAtRoute("DefaultApi", new { id = commentaire.ID }, commentaire); }
public IHttpActionResult PutJournaliste(int id, Journalistes journalistes) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != journalistes.ID) { return(BadRequest()); } db.Entry(journalistes).State = EntityState.Modified; db.SaveChanges(); return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutChefRedaction(int id, RedacteurEnChef redacteurEnChef) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != redacteurEnChef.ID) { return(BadRequest()); } db.Entry(redacteurEnChef).State = EntityState.Modified; db.SaveChanges(); return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutArticle(int id, Article article) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != article.ID) { return(BadRequest()); } db.Entry(article).State = EntityState.Modified; db.SaveChanges(); return(StatusCode(HttpStatusCode.NoContent)); }
public void Update(PostGallery Instance) { using (var db = new NEWSEntities()) { try { var existItem = db.PostGalleries.SingleOrDefault(d => d.ID == Instance.ID); existItem.ID = Instance.ID; existItem.Name = Instance.Name; db.SaveChanges(); } catch (Exception ex) { throw new AggregateException(ex); } } }
public void Update(Category Instance) { using (var db = new NEWSEntities()) { try { var existItem = db.Categories.SingleOrDefault(d => d.ID == Instance.ID); existItem.Name = Instance.Name; existItem.CategoryType = Instance.CategoryType; existItem.ParentId = Instance.ParentId; db.SaveChanges(); } catch (Exception ex) { throw new AggregateException(ex); } } }
public void Delete(long ID) { using (var db = new NEWSEntities()) { try { var existItem = db.Categories.SingleOrDefault(d => d.ID == ID); if (existItem == null) { throw new AggregateException("مورد یافت نشد."); } db.Categories.Remove(existItem); db.SaveChanges(); } catch (Exception ex) { throw new AggregateException(ex); } } }
public void Update(Comment Instance) { using (var db = new NEWSEntities()) { try { var existItem = db.Comments.SingleOrDefault(d => d.ID == Instance.ID); existItem.Title = Instance.Title; existItem.PersonName = Instance.PersonName; existItem.Email = Instance.Email; existItem.Title = Instance.Title; existItem.Desciption = Instance.Desciption; existItem.Website = Instance.Website; existItem.PostID = Instance.PostID; db.SaveChanges(); } catch (Exception ex) { throw new AggregateException(ex); } } }