Example #1
0
 public bool SaveReport(DbEntities.Subjects.Report report)
 {
     try
     {
         var earlier = Context.Report.FirstOrDefault(x => x.SubjectClassId == report.SubjectClassId);
         if (earlier == null)
         {
             //add
             Context.Report.Add(report);
             Context.SaveChanges();
             return(true);
         }
         else
         {
             //update
             earlier.ShowActivityResourceIds = report.ShowActivityResourceIds;
             earlier.ShowCRN   = report.ShowCRN;
             earlier.ShowImage = report.ShowImage;
             earlier.ShowName  = report.ShowName;
             earlier.ShowTotal = report.ShowTotal;
             Context.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
Example #2
0
            public AssignmentSubmissions AddOrUpdateAssignmentSubmission(AssignmentSubmissions submission
                                                                         , List <Academic.DbEntities.UserFile> files)
            {
                try
                {
                    var date = DateTime.Now;
                    var ent  = Context.AssignmentSubmissions.Find(submission.Id);
                    if (ent == null)
                    {
                        ent = Context.AssignmentSubmissions.Add(submission);
                        Context.SaveChanges();
                        foreach (var f in files.Where(x => !(x.Void ?? false)))
                        {
                            var savedFile = Context.File.Add(f);
                            Context.SaveChanges();

                            var savedFileResFile = Context.AssignmentSubmissionFiles.Add(new AssignmentSubmissionFiles()
                            {
                                AssignmentSubmissionsId = ent.Id
                                ,
                                UserFileId = savedFile.Id
                                ,
                                FileSubmittedDate = date
                                ,
                            });
                            Context.SaveChanges();
                        }
                    }
                    else
                    {
                        ent.ModifiedDate   = submission.ModifiedDate;
                        ent.SubmissionText = submission.SubmissionText;
                        Context.SaveChanges();

                        foreach (var f in files)
                        {
                            var earlier = Context.File.Find(f.Id);
                            if (earlier == null)
                            {
                                var savedFile = Context.File.Add(f);
                                Context.SaveChanges();

                                var savedFileResFile = Context.AssignmentSubmissionFiles.Add(new AssignmentSubmissionFiles()
                                {
                                    AssignmentSubmissionsId = ent.Id
                                    ,
                                    UserFileId = savedFile.Id
                                    ,
                                    FileSubmittedDate = date
                                    ,
                                });
                                Context.SaveChanges();
                            }
                            else
                            {
                                earlier.Void = f.Void;
                                if (f.Void ?? false)
                                {
                                    var fnd = Context.AssignmentSubmissionFiles.FirstOrDefault(
                                        x => x.AssignmentSubmissionsId == ent.Id && x.UserFileId == earlier.Id);
                                    if (fnd != null)
                                    {
                                        Context.AssignmentSubmissionFiles.Remove(fnd);
                                        Context.SaveChanges();
                                    }
                                }
                            }
                        }
                    }
                    return(ent);
                }
                catch
                {
                    return(null);
                }
            }