/// <summary> /// Throws exceptions if the ItemReport is invalid /// </summary> /// <param name="item_report"></param> /// <returns></returns> protected void AssertItemReportValid(ItemReport item_report) { IEnumerable <string> broken_rules = ItemReportValidator.BrokenRules(item_report); if (broken_rules.Count() > 0) { throw new DataInvalidException(broken_rules); } }
protected void AddItemReportInOrder(ItemReport ir_to_insert) { int i = 0; foreach (ItemReport ir in EditableLocalItemReports) { if (ir.ReportTime < ir_to_insert.ReportTime) { EditableLocalItemReports.Insert(i, ir_to_insert); return; } i++; } EditableLocalItemReports.Add(ir_to_insert); }
public override async Task <int> SubmitItem(ItemReport item_report) { AssertItemReportValid(item_report); if (item_report.ID == 0) // no ID, create new { int max_or_zero = EditableLocalItemReports.Count() > 0 ? EditableLocalItemReports.Max(ir => ir.ID) : 0; int id = max_or_zero + 1; item_report.ID = id; item_report.ReportTime = DateTime.Now; item_report.EditTime = item_report.ReportTime; item_report.IsMine = true; //EditableLocalItemReports.Add(item_report); AddItemReportInOrder(item_report); return(id); } else { int i = 0; foreach (ItemReport ir in EditableLocalItemReports) { if (ir.ID == item_report.ID) { if (!ir.IsMine) { // this should be verified server-side as well throw new Exception( "You do not have permission to edit this item report."); } item_report.ReportTime = ir.ReportTime; item_report.EditTime = DateTime.Now; item_report.IsMine = true; EditableLocalItemReports.RemoveAt(i); EditableLocalItemReports.Insert(i, item_report); return(item_report.ID); } i++; } throw new InvalidOperationException("No item report" + " with this ID exists, so it cannot be edited"); } }
/// <summary> /// SubmitItem is responsible for the ItemReport's ID, IsMine, /// ReportTime and EditTime fields /// </summary> /// <param name="item_report"></param> /// <returns></returns> public abstract Task <int> SubmitItem(ItemReport item_report);
/// <summary> /// Attempts to send the item_report to the cloud. /// </summary> /// <param name="item_report"></param> public override async Task <int> SubmitItem(ItemReport item_report) { throw new NotImplementedException(); }
public ItemReportEventArgs(ItemReport item_report) { this.ItemReport = item_report; }