Пример #1
0
        public ContentResult AddHomeWork(HomeWork homeWork, int courseId)
        {
            RequestStatus result = new RequestStatus();

            try
            {
                Course course = context.Courses.Find(courseId);
                if (course.Teacher.ApplicationUser.Id == currentUserId)
                {
                    homeWork.InitProjects(course);
                    if (homeWork.Attachments != null)
                    {
                        FileData.DataBase64ToDataByteArr(homeWork.Attachments);
                        FileData.BuindGuid(homeWork.Attachments);
                    }
                    context.Homeworks.Add(homeWork);
                    context.SaveChanges();
                    result.Result       = true;
                    result.ErrorMessage = "No errors";
                }
            }
            catch (Exception ex)
            {
                result.Result       = false;
                result.ErrorMessage = ex.Message;
            }
            var json = new JavaScriptSerializer().Serialize(result);

            return(new ContentResult()
            {
                Content = json,
                ContentType = ApplicationConstants.JSON_TYPE
            });
        }