private Topic CreateModel(TopicBindingModel model, Topic topic) { topic.Name = model.Name; topic.Numberofmessages = model.NumberOfMessages; topic.Numberofvisitors = model.NumberOfVisitors; return(topic); }
public async Task <IHttpActionResult> UpdatePost([FromBody] TopicBindingModel model) { try { ApplicationUser user = this.userRepository.GetOneById(User.Identity.GetUserId()); Topic t = this.repository.GetOneById(model.Id); if (t.creatorId == user.Id || User.IsInRole("Admin")) { repository.UpdateOne(new Topic { Id = model.Id, Title = model.Title, CreationDate = model.CreationDate }); return(Ok("Topic Updated")); } else { return(BadRequest("Cannot update a Topic which you are not an admin of!")); } } catch { return(BadRequest("Bad Request")); } }
public void Insert(TopicBindingModel model) { using (var context = new ForumDatabase()) { context.Topic.Add(CreateModel(model, new Topic())); context.SaveChanges(); } }
public ActionResult Create(TopicBindingModel topic) { if (!this.ModelState.IsValid) { return(this.View(topic)); } this.dataService.CreateNewTopic(topic, this.User); return(this.RedirectToAction("Index", "Topic")); }
public void Delete(TopicBindingModel model) { var element = topicStorage.GetElement(new TopicBindingModel { Name = model.Name }); if (element == null) { throw new Exception("Элемент не найден"); } topicStorage.Delete(model); }
public void Update(TopicBindingModel model) { using (var context = new ForumDatabase()) { var element = context.Topic.FirstOrDefault(rec => rec.Name == model.Name); if (element == null) { throw new Exception("Элемент не найден"); } CreateModel(model, element); context.SaveChanges(); } }
public void CreateOrUpdate(TopicBindingModel model) { if (topicStorage.GetElement(new TopicBindingModel { Name = model.Name }) != null) { topicStorage.Update(model); } else { topicStorage.Insert(model); } }
public List <TopicViewModel> Read(TopicBindingModel model) { if (model == null) { return(topicStorage.GetFullList()); } if (!model.Name.Equals(null)) { return(new List <TopicViewModel> { topicStorage.GetElement(model) }); } return(topicStorage.GetFilteredList(model)); }
public void CreateNewTopic(TopicBindingModel topic, IPrincipal user) { using (var context = this.GetDbContext) { context.Topics.Add(new Topic { Category = topic.Category, UserId = user.Identity.GetUserId(), TopicDate = DateTime.UtcNow, Text = topic.Text, Title = topic.Title }); context.SaveChanges(); } }
public void Delete(TopicBindingModel model) { using (var context = new ForumDatabase()) { var element = context.Topic.FirstOrDefault(rec => rec.Name == model.Name); if (element != null) { context.Topic.Remove(element); context.SaveChanges(); } else { throw new Exception("Элемент не найден"); } } }
public TopicViewModel GetElement(TopicBindingModel model) { if (model == null) { return(null); } using (var context = new ForumDatabase()) { var topic = context.Topic.Include(rec => rec.Message).FirstOrDefault (rec => rec.Name == model.Name); return(topic != null ? new TopicViewModel { Name = topic.Name, NumberOfVisitors = topic.Numberofvisitors, NumberOfMessages = topic.Numberofmessages } : null); } }
public async Task <IHttpActionResult> CreatePost([FromBody] TopicBindingModel model) { try { ApplicationUser user = this.userRepository.GetOneById(User.Identity.GetUserId()); if (user == null) { return(BadRequest("Bad Token! No User present!")); } repository.CreateOne(new Topic { Title = model.Title, CreationDate = model.CreationDate, isPrivate = model.isPrivate, creatorId = user.Id }); return(Ok("Topic Created")); } catch (Exception e) { return(BadRequest(e.Message)); } }
public List <TopicViewModel> GetFilteredList(TopicBindingModel model) { throw new NotImplementedException(); }