private HttpResponseMessage SavePercentage(PercentageGraphData percentage)
 {
     if (!ModelState.IsValid)
     {
         return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
     }
     
     PercentageService.SavePercentage(WebSecurity.CurrentUserId, percentage);
     return new HttpResponseMessage(HttpStatusCode.OK);
 }
예제 #2
0
        public void SavePercentage(int userId, PercentageGraphData percentageData)
        {
            AuthorizationHelper.ValidateLecturerAccess(Context, userId);

            if (Context.CoursePercentagesGraphs.Any(x => x.Name == percentageData.Name))
            {
                throw new ApplicationException("Этап с таким названием уже есть!");
            }

            CoursePercentagesGraph percentage;
            if (percentageData.Id.HasValue)
            {
                percentage = Context.CoursePercentagesGraphs
                              .Include(x => x.CoursePercentagesGraphToGroups)
                              .Single(x => x.Id == percentageData.Id);
            }
            else
            {
                percentage = new CoursePercentagesGraph();
                Context.CoursePercentagesGraphs.Add(percentage);
                percentage.SubjectId = percentageData.SubjectId;
            }

            percentage.LecturerId = userId;
            percentage.Name = percentageData.Name;
            percentage.Percentage = percentageData.Percentage;
            percentage.Date = percentageData.Date;
            //percentage.SubjectId = percentageData.SubjectId;

            Context.SaveChanges();
        }