Esempio n. 1
0
        public int CreateNewReport(Report report)
        {
            ReportEntity reportEntity = new ReportEntity()
            {
                AuthorityId = report.AuthorityId,
                UserId = report.UserId,
                Description = report.Description,
                Date = report.Date,
                Location = report.Location,
                Photo = report.Photo,
                Mood = report.Mood,
            };

            using (DobbermanEntities context = new DobbermanEntities())
            {
                AuthorityEntity reportAuthority = (from p
                                        in context.Authorities
                                                where p.AuthorityId == reportEntity.AuthorityId
                                                select p).FirstOrDefault();
                switch (report.Mood)
                {
                    case "positive":
                        reportAuthority.AccumulatedScore += 100;
                        break;
                    case "concerned":
                        reportAuthority.AccumulatedScore += 50;
                        break;
                    case "negative":
                        //add zero to AccumulatedScore
                        break;
                }
                // change the score of authority to the new weighted score
                reportAuthority.Score = reportAuthority.AccumulatedScore / (reportAuthority.Reports.Count + 1);
                // add new report to the context
                context.AddToReports(reportEntity);
                context.SaveChanges();
            }
            return reportEntity.ReportId;
        }
Esempio n. 2
0
 private Report TranslateReportEntityToReport(ReportEntity reportEntity)
 {
     Report report = new Report()
     {
         ReportId = reportEntity.ReportId,
         Date = reportEntity.Date,
         Description = reportEntity.Description,
         Mood = reportEntity.Mood,
         Photo = reportEntity.Photo,
         Location = reportEntity.Location,
         FacebookLink = reportEntity.FacebookLink,
         UserId = reportEntity.UserId,
         AuthorityId = reportEntity.AuthorityId,
         User = TranslateUserEntityToUser(reportEntity.User),
         Authority = TranslateAuthorityEntityToAuthority(reportEntity.Authority),
     };
     return report;
 }