コード例 #1
0
        public HttpResponseMessage PostReport([FromBody] ReportDTO reportDTO)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, reportDTO));
            }

            using (var repo = new ReportRepository())
            {
                var report = new Report
                {
                    Lat            = reportDTO.Location.Lat,
                    Long           = reportDTO.Location.Long,
                    Type           = "Interaction",
                    Address        = reportDTO.Location.Cross_Street,
                    Narrative      = reportDTO.Location.Narrative,
                    Mode           = reportDTO.Mode,
                    Description    = reportDTO.Description,
                    CreatedOn      = DateTime.Now,
                    Infrastructure = reportDTO.Infrastructure,
                    Collision      = reportDTO.Collision,
                    PropertyDamage = reportDTO.PropertyDamage,
                    Injury         = reportDTO.Injury,
                    CollisionModes = string.Join(",", reportDTO.Modes.Other)
                };

                repo.Add(report);
                repo.Commit();
                reportDTO.Id = report.Id;

                return(Request.CreateResponse(HttpStatusCode.OK, reportDTO));
            }
        }
コード例 #2
0
        public void ShouldAddReports()
        {
            using (var repo = new ReportRepository())
            {
                var reports = new List <Report>()
                {
                    new Report {
                        Location = new GeoLocation
                        {
                            Lat       = 45.712113f,
                            Long      = -121.527200f,
                            Address   = "301 15th Street, Hood River",
                            Narrative = "test"
                        },
                        Type = "Interaction"
                    },
                    new Report {
                        Location = new GeoLocation
                        {
                            Lat       = -45.708457f,
                            Long      = -121.514432f,
                            Address   = "Kaze Sushi, Hood River",
                            Narrative = "test"
                        },
                        Type = "Interaction"
                    },
                };
                foreach (var report in reports)
                {
                    repo.Add(report);
                }

                repo.Commit();
            }
        }
コード例 #3
0
 public ActionResult Create(Report report)
 {
     if (ModelState.IsValid)
     {
         reportRepository.Add(report);
         return(RedirectToAction("Index", "Report"));
     }
     return(View(report));
 }
コード例 #4
0
        public void Add_A_Report_When_Not_Populated_Should_Be_One()
        {
            var repository = new ReportRepository(fixture.context);
            var entity     = ReportEntityTypeConfiguration.ReportSeed.ElementAt(1);

            entity.Id = 3;
            repository.Add(entity);
            var count = repository.Get().Count();

            Assert.Equal(1, count);
        }
コード例 #5
0
        /// <summary>
        /// 模具测试
        /// </summary>
        /// <param name="moldNR">模具号</param>
        /// <param name="operatorNR">操作员工号</param>
        /// <param name="files">文件列表</param>
        /// <returns>测试信息</returns>
        public Message  MoldTest(string moldNR, string operatorNR, FileUP[] files, int currentCutTimes, bool moldNormal)
        {
            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    using (IUnitOfWork unitwork = MSSqlHelper.DataContext())
                    {
                        IReportRepository reportRep = new ReportRepository(unitwork);

                        Report report = new Report();
                        report.ReportId   = GuidUtil.GenerateGUID();
                        report.MoldID     = moldNR;
                        report.ReportType = ReportType.TestReport;
                        report.OperatorID = operatorNR;
                        report.Date       = DateTime.Now;

                        //upload files
                        FileUpLoad(files, report.ReportId.ToString());

                        reportRep.Add(report);

                        // update the last released date
                        IMoldRepository moldRep = new MoldRepository(unitwork);
                        Mold            mold    = moldRep.GetById(moldNR);
                        mold.LastReleasedDate = report.Date;
                        mold.Cuttedtimes     += mold.CurrentCuttimes;
                        mold.CurrentCuttimes  = 0;
                        if (moldNormal)
                        {
                            mold.State = MoldStateType.Normal;
                        }
                        unitwork.Submit();

                        ts.Complete();

                        return(new Message()
                        {
                            MsgType = MsgType.OK, Content = "实验报告上传成功!"
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                LogUtil.log.Error(ex.ToString());
                return(new Message()
                {
                    MsgType = MsgType.Error, Content = ex.Message
                });
            }
        }
コード例 #6
0
        public void AddReport()
        {
            RestoreDate();

            var reportRepository = new ReportRepository(mockContext.Object);

            Report report = new Report
            {
                Listener = new Student(),
                Mark     = 60
            };

            reportRepository.Add(report);

            Assert.IsNotNull(_Reports.Where(s => report.Id == s.Id).FirstOrDefault());
            Assert.AreEqual(reportRepository.Get(report.Id).Id, report.Id);
        }
コード例 #7
0
        public void GetReportById()
        {
            RestoreDate();

            var ReportRepository = new ReportRepository(mockContext.Object);

            Report report = new Report
            {
                Listener = new Student(),
                Mark     = 60
            };

            ReportRepository.Add(report);

            Assert.IsNotNull(_Reports.FirstOrDefault());
            Assert.IsNotNull(ReportRepository.Get(report.Id));
        }
コード例 #8
0
        public void DeleteReport()
        {
            RestoreDate();

            var ReportRepository = new ReportRepository(mockContext.Object);

            Report report = new Report
            {
                Listener = new Student(),
                Mark     = 60
            };


            ReportRepository.Add(report);

            ReportRepository.Remove(report);

            Assert.IsNull(_Reports.Where(s => report.Id == s.Id).FirstOrDefault());
        }
コード例 #9
0
        public HttpResponseMessage GetLoadData()
        {
            using (var repo = new ReportRepository())
            {
                var reports = new List <Report>()
                {
                    new Report {
                        Lat            = 47.608746f,
                        Long           = -122.336894f,
                        Address        = "301 15th Street, Hood River",
                        Narrative      = "test",
                        Mode           = "Bike",
                        Description    = "Doored on 2nd n seneca",
                        CreatedOn      = new DateTime(2015, 3, 20),
                        Type           = "Interaction",
                        Infrastructure = true,
                        Collision      = false,
                        PropertyDamage = false,
                        Injury         = false,
                        CollisionModes = "",
                    },
                    new Report {
                        Lat            = 47.60731f,
                        Long           = -122.337066f,
                        Address        = "Kaze Sushi, Hood River",
                        Narrative      = "test",
                        Mode           = "Walk",
                        Description    = "Trip and fell on the sidewalk",
                        CreatedOn      = new DateTime(2015, 3, 20),
                        Type           = "Interaction",
                        Infrastructure = true,
                        Collision      = true,
                        PropertyDamage = true,
                        Injury         = true,
                        CollisionModes = "Car,Walk",
                    },
                    new Report {
                        Lat            = 47.606127f,
                        Long           = -122.337538f,
                        Address        = "Kaze Sushi",
                        Narrative      = "test",
                        Mode           = "Walk",
                        Description    = "Trip and fell on the sidewalk",
                        CreatedOn      = new DateTime(2015, 3, 20),
                        Type           = "Interaction",
                        Infrastructure = false,
                        Collision      = true,
                        PropertyDamage = false,
                        Injury         = true,
                        CollisionModes = "Car",
                    },
                    new Report {
                        Lat            = 47.606818f,
                        Long           = -122.333536f,
                        Address        = "Kaze Sushi/Hood River",
                        Narrative      = "test",
                        Mode           = "Walk",
                        Description    = "Trip and fell on the sidewalk",
                        CreatedOn      = new DateTime(2015, 3, 20),
                        Type           = "Interaction",
                        Infrastructure = true,
                        Collision      = true,
                        PropertyDamage = true,
                        Injury         = false,
                        CollisionModes = "Walk",
                    },
                    new Report {
                        Lat            = 47.606561f,
                        Long           = -122.334115f,
                        Address        = "Kaze Sushi / Hood River",
                        Narrative      = "test",
                        Mode           = "Walk",
                        Description    = "Trip and fell on the sidewalk",
                        CreatedOn      = new DateTime(2015, 3, 20),
                        Type           = "Interaction",
                        Infrastructure = true,
                        Collision      = true,
                        PropertyDamage = true,
                        Injury         = true,
                        CollisionModes = "Walk",
                    },
                    new Report {
                        Lat            = 47.606702f,
                        Long           = -122.334984f,
                        Address        = "Kaze Sushi, Hood River",
                        Narrative      = "test",
                        Mode           = "Walk",
                        Description    = "Trip and fell on the sidewalk",
                        CreatedOn      = new DateTime(2015, 3, 20),
                        Type           = "Interaction",
                        Infrastructure = true,
                        Collision      = true,
                        PropertyDamage = true,
                        Injury         = true,
                        CollisionModes = "Car,Walk",
                    },
                    new Report {
                        Lat            = 47.608297f,
                        Long           = -122.336454f,
                        Address        = "Kaze Sushi, Hood River",
                        Narrative      = "test",
                        Mode           = "Walk",
                        Description    = "Trip and fell on the sidewalk",
                        CreatedOn      = new DateTime(2015, 3, 20),
                        Type           = "Interaction",
                        Infrastructure = true,
                        Collision      = true,
                        PropertyDamage = true,
                        Injury         = true,
                        CollisionModes = "Car,Walk",
                    },
                    new Report {
                        Lat            = 47.609509f,
                        Long           = -122.338364f,
                        Address        = "Kaze Sushi, Hood River",
                        Narrative      = "test",
                        Mode           = "Walk",
                        Description    = "Trip and fell on the sidewalk",
                        CreatedOn      = new DateTime(2015, 3, 20),
                        Type           = "Interaction",
                        Infrastructure = true,
                        Collision      = true,
                        PropertyDamage = true,
                        Injury         = true,
                        CollisionModes = "Car,Walk",
                    },
                    new Report {
                        Lat            = 47.611639f,
                        Long           = -122.339523f,
                        Address        = "Kaze Sushi, Hood River",
                        Narrative      = "test",
                        Mode           = "Walk",
                        Description    = "Trip and fell on the sidewalk",
                        CreatedOn      = new DateTime(2015, 3, 20),
                        Type           = "Interaction",
                        Infrastructure = true,
                        Collision      = true,
                        PropertyDamage = true,
                        Injury         = true,
                        CollisionModes = "Car,Walk",
                    }
                };
                foreach (var report in reports)
                {
                    repo.Add(report);
                }

                repo.Commit();
            }
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
コード例 #10
0
 public IActionResult Report(Report report)
 {
     _reportRepository.Add(report);
     return(CreatedAtAction(nameof(Get), new { id = report.Id }, report));
 }
コード例 #11
0
 internal Report Add(Report report)
 => _reportRepository.Add(report);