public IActionResult Post([FromBody] TopicFormModel model)
        {
            if (!_topicPermissions.IsAllowedToCreate(User.Identity.GetUserIdentity()))
            {
                return(Forbidden());
            }

            if (ModelState.IsValid)
            {
                if (!TopicStatus.IsStatusValid(model.Status))
                {
                    ModelState.AddModelError("Status", "Invalid Topic Status");
                }
                else
                {
                    var result = _topicManager.AddTopic(User.Identity.GetUserIdentity(), model);
                    if (result.Success)
                    {
                        return(Ok(result));
                    }
                }
            }

            return(BadRequest(ModelState));
        }
        public void PutTopicTest400()
        {
            var topicFormModel = new TopicFormModel();

            _tester.TestControllerWithMockData()
            .Calling(c => c.Put(_tester.TopicOne.Id, topicFormModel))
            .ShouldReturn()
            .BadRequest();
        }
        public void PostTopicTest400()
        {
            var topicFormModel = new TopicFormModel();

            _tester.TestController()
            .Calling(c => c.Post(topicFormModel))
            .ShouldReturn()
            .BadRequest();
        }
Beispiel #4
0
        public Topic(TopicFormModel model)
        {
            Title  = model.Title;
            Status = model.Status;
            if (model.Deadline != null)
            {
                Deadline = (DateTime)model.Deadline;
            }
            Description  = model.Description;
            Requirements = model.Requirements;

            TopicUsers       = new List <TopicUser>();
            AssociatedTopics = new List <AssociatedTopic>();
        }
 public TopicsControllerTest()
 {
     _tester        = new ControllerTester <TopicsController>();
     TopicFormModel = new TopicFormModel
     {
         Title       = "Schloss Neuhaus",
         Status      = "InReview",
         Description = "Castle"
     };
     TopicStatus = new TopicStatus
     {
         Status = "InProgress"
     };
 }
Beispiel #6
0
        public void OnUpdate(TopicFormModel changes)
        {
            // Deadline Changed
            if (changes.Deadline != topic.Deadline)
            {
                NotifyAll(NotificationType.TOPIC_DEADLINE_CHANGED, changes.Deadline.ToString());
            }
            else if ((changes.Status != topic.Status))
            {
                NotifyAll(NotificationType.TOPIC_STATE_CHANGED, changes.Status);
            }
            else
            {
                NotifyAll(NotificationType.TOPIC_UPDATED);
            }

            finnish();
        }
        public IActionResult Put([FromRoute] int topicId, [FromBody] TopicFormModel model)
        {
            if (!_topicPermissions.IsAllowedToEdit(User.Identity.GetUserIdentity(), topicId))
            {
                return(Forbidden());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // TODO createUser is Supervisor!
            if (_topicManager.UpdateTopic(User.Identity.GetUserIdentity(), topicId, model))
            {
                return(Ok());
            }
            return(BadRequest(ModelState));
        }
Beispiel #8
0
        public EntityResult AddTopic(int userId, TopicFormModel model)
        {
            try
            {
                var topic = new Topic(model)
                {
                    CreatedById = userId
                };
                DbContext.Topics.Add(topic);
                DbContext.SaveChanges();
                new NotificationProcessor(DbContext, topic, userId).OnNewTopic();

                return(EntityResult.Successfull(topic.Id));
            }
            catch (Exception e)
            {
                return(EntityResult.Error(e.Message));
            }
        }
        public bool UpdateTopic(string identity, int topicId, TopicFormModel model)
        {
            // Using Transactions to roobback Notifications on error.
            using (var transaction = DbContext.Database.BeginTransaction())
                try
                {
                    var topic = DbContext.Topics.Include(t => t.TopicUsers).Single(t => t.Id == topicId);
                    // REM: do before updating to estimate the changes
                    new NotificationProcessor(DbContext, topic, identity).OnUpdate(model);

                    // TODO  topic.UpdatedById = userId;
                    topic.Title  = model.Title;
                    topic.Status = model.Status;
                    if (model.Deadline != null)
                    {
                        topic.Deadline = (DateTime)model.Deadline;
                    }
                    topic.Description  = model.Description;
                    topic.Requirements = model.Requirements;

                    DbContext.SaveChanges();
                    transaction.Commit();
                    return(true);
                }
                catch (InvalidOperationException)
                {
                    //Not found
                    return(false);
                }
            catch (Exception ex)
            {
                transaction.Rollback();
                Console.WriteLine(ex.ToString());
                return(false);
            }
        }