public ActionResult AddTopic(string name)
        {
            TopicRepository repo    = new TopicRepository();
            string          message = string.Empty;
            bool            errored = false;

            if (string.IsNullOrEmpty(name))
            {
                errored = true;
                message = "Missing value";
            }
            else
            {
                try
                {
                    repo.AddTopic(name);
                }
                catch (Exception exc)
                {
                    errored = true;
                    message = exc.ToString();
                }
            }

            if (!errored)
            {
                message = "Changes Saved";
            }

            return(Json(new { Errored = errored, Message = message }, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        public void CreateFanfic([FromBody] FanficScriptModel data)
        {
            string userId             = User.Identity.GetUserId();
            PreviewUserViewModel user = Mapper
                                        .Map <PreviewUserViewModel>(ApplicationUserRepository.GetApplicationUserById(data.UserId));

            if (user != null && User.IsInRole("admin"))
            {
                userId = user.Id;
            }
            Fanfic fanfic = new Fanfic
            {
                ApplicationUserId = userId,
                AverageRating     = 0,
                CategoryId        = data.Category,
                CreateDate        = DateTime.Now,
                Description       = data.Description,
                ImgUrl            = data.ImgUrl,
                Name = data.Name
            };
            int id = FanficRepository.AddFanfic(fanfic);

            foreach (var topicScript in data.Topics)
            {
                Topic topic = new Topic
                {
                    Name          = topicScript.Name,
                    Number        = topicScript.Number,
                    FanficId      = id,
                    Text          = topicScript.Text,
                    ImgUrl        = topicScript.ImgUrl,
                    AverageRating = 0
                };
                TopicRepository.AddTopic(topic);
            }
            foreach (var tag in data.Tags)
            {
                FanficTagRepository.AddNewFanficTag(id, TagRepository.FindOrAdd(tag.Name));
            }
        }
示例#3
0
        public IHttpActionResult AddTopic([FromBody] string search)
        {
            JObject Json = new JObject();

            using (StreamReader sr = new StreamReader(HttpContext.Current.Request.InputStream))
            {
                Json = JsonConvert.DeserializeObject <JObject>(sr.ReadToEnd());
            }

            string TeacherId;
            string Group;
            string Title;
            string Description;
            long   Date;
            string SubjectId;

            try
            {
                TeacherId   = Json.Descendants().OfType <JProperty>().First(p => p.Name == "TeacherId").Value.ToString();
                Group       = Json.Descendants().OfType <JProperty>().First(p => p.Name == "Group").Value.ToString();
                Title       = Json.Descendants().OfType <JProperty>().First(p => p.Name == "Title").Value.ToString();
                Description = Json.Descendants().OfType <JProperty>().First(p => p.Name == "Description").Value.ToString();
                SubjectId   = Json.Descendants().OfType <JProperty>().First(p => p.Name == "SubjectId").Value.ToString();
            }
            catch (System.InvalidOperationException)
            {
                return(Content(HttpStatusCode.NotFound, "The request must contain a field query"));
            }
            catch (System.FormatException)
            {
                return(Content(HttpStatusCode.NotFound, "from and size it must be non-negative integer"));
            }

            _topicRepository.AddTopic(new Topic(TeacherId, Group, Title, Description, DateTime.Now.Ticks, SubjectId));
            return(Ok());
        }
示例#4
0
 public Topic AddTopic(Topic topic)
 {
     return(_topicRepository.AddTopic(topic));
 }