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; }
/// <summary> /// Create a new ReportEntity object. /// </summary> /// <param name="reportId">Initial value of the ReportId property.</param> /// <param name="date">Initial value of the Date property.</param> /// <param name="description">Initial value of the Description property.</param> /// <param name="userId">Initial value of the UserId property.</param> /// <param name="authorityId">Initial value of the AuthorityId property.</param> /// <param name="mood">Initial value of the Mood property.</param> public static ReportEntity CreateReportEntity(global::System.Int32 reportId, global::System.DateTime date, global::System.String description, global::System.Int32 userId, global::System.Int32 authorityId, global::System.String mood) { ReportEntity reportEntity = new ReportEntity(); reportEntity.ReportId = reportId; reportEntity.Date = date; reportEntity.Description = description; reportEntity.UserId = userId; reportEntity.AuthorityId = authorityId; reportEntity.Mood = mood; return reportEntity; }
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; }
/// <summary> /// Deprecated Method for adding a new object to the Reports EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToReports(ReportEntity reportEntity) { base.AddObject("Reports", reportEntity); }