Exemple #1
0
        public IHttpActionResult Post([FromBody] EmailReportViewModel data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }
            if (data.UserId == -1 && !User.IsInRole(ConnectRoles.Admin))
            {
                return(Unauthorized());
            }

            using (var context = new ConnectContext())
            {
                switch (data.ReportType)
                {
                case ApiReportType.RecentCalibrations:
                    var recentCalibrations = context.RecentCalibrations(ConnectUser, data.UserId, data.From);
                    SendEmail(data.Recipient, "Your Recent Calibrations Report", EmailHelper.GetCalibrationDataTable(recentCalibrations));
                    break;

                case ApiReportType.CalibrationsDue:
                    var calibrationsDue = context.CalibrationsDue(ConnectUser, data.UserId, data.From, data.To.GetValueOrDefault());
                    SendEmail(data.Recipient, "Your Calibrations Due Report", EmailHelper.GetCalibrationDataTable(calibrationsDue));
                    break;
                }
            }

            return(Ok());
        }
        public IHttpActionResult Get(int userId, DateTime from, DateTime to)
        {
            if (userId == -1 && !User.IsInRole(ConnectRoles.Admin))
            {
                return(Unauthorized());
            }

            using (var context = new ConnectContext())
            {
                var data = context.CalibrationsDue(ConnectUser, userId, from, to);
                return(Ok(data));
            }
        }