示例#1
0
        public ActionResult Create(TaskViewModel task)
        {
            Task newTask = new Task
            {
                TaskText    = EscapeHtml(task.TaskText),
                Title       = EscapeHtml(task.Title),
                Added       = DateTime.Now,
                Author      = WebSecurity.CurrentUserId,
                UserProfile = data.FindUser(WebSecurity.CurrentUserId)
            };

            var categoryNames = JsonConvert.DeserializeObject <List <string> >(JsonConvert.DeserializeObject <string>(task.Categories));

            foreach (string s in categoryNames)
            {
                data.AddCategory(s);
                newTask.Categories.Add(data.GetCategory(s));
            }
            var solutions = task.Answers.Split(',');

            foreach (var solution in solutions)
            {
                data.AddAnsver(solution);
            }
            data.modifiUserProfileSuccess();
            data.AddTask(newTask);
            return(RedirectToAction("Index", "Home"));
        }