예제 #1
0
 public IActionResult AddSections([FromBody] SectionsCreateModel model)
 {
     if (ModelState.IsValid)
     {
         string errorMessage = string.Empty;
         int?   count        = service.AddSections(model, ref errorMessage);
         if (count.HasValue)
         {
             Result result = new Result(true)
             {
                 PortalMessages = String.Format(PortalMessages.CreatedSectionsSuccesfull, count.Value)
             };
             return(Json(result));
         }
         return(Json(new Result(errorMessage)));
     }
     return(Json(new Result(ModelState.GetFirstError())));
 }
예제 #2
0
        public int?AddSections(SectionsCreateModel model, ref string errorMessage)
        {
            int MAX_SECTIONS = 50;
            int c;
            int?subSemId;
            int notCreated = 0;

            using (SZPNUWContext context = new SZPNUWContext())
            {
                subSemId = context.Subjectssemesters.Where(x => x.Subjectid == model.SubjectId && x.Semesterid == model.SemesterId).Select(x => x.Id).FirstOrDefault();
                if (subSemId.HasValue)
                {
                    c = context.Sections.Where(s => s.Subcjetsemesterid == subSemId).ToList().Count;
                    int i = 0;
                    while (i < model.Count && c < MAX_SECTIONS)
                    {
                        try
                        {
                            context.Sections.Add(new Sections {
                                Subcjetsemesterid = subSemId.Value, Sectionnumber = c + 1
                            });
                            context.SaveChanges();
                            c++;
                        }
                        catch (Exception ex)
                        {
                            notCreated++;
                        }
                        i++;
                    }
                    return(model.Count - notCreated);
                }
                errorMessage = PortalMessages.NoSubjectOnSemester;
                return(null);
            }
        }
예제 #3
0
 public int?AddSections(SectionsCreateModel model, ref string errorMessage)
 {
     return(service.AddSections(model, ref errorMessage));
 }