コード例 #1
0
        private HttpResponseMessage ProcessNewO2Record(HttpRequestMessage request, O2ReadingDTO uDto, string key, int companyId, int UserId)
        {
            var ur = new O2ReadingRepository();
            var o2 = new O2Reading();

            var validationErrors = GetO2ValidationErrors(ur, o2, uDto, companyId, UserId);

            if (validationErrors.Any())
            {
                return ProcessValidationErrors(request, validationErrors, key);
            }
            //  no validation errors...
            //Pond.CompanyId = companyId;

            o2 = ur.Save(o2);

            UpdatePondHealthStatusByLevel(o2.PondId, o2.O2Level);
            uDto.Key = key;
            uDto.ReadingId = o2.ReadingId.ToString();
            var response = request.CreateResponse(HttpStatusCode.Created, uDto);
            response.Headers.Location = new Uri(Url.Link("Default", new
            {
                id = o2.ReadingId
            }));
            return response;
        }
コード例 #2
0
        private HttpResponseMessage ProcessExistingO2Record(HttpRequestMessage request, O2ReadingDTO cqDto, int contactId, string key, int companyId, int UserId)
        {
            var o2r = new O2ReadingRepository();
            var o2 = new O2Reading();
            o2 = o2r.GetById(contactId);
            //  is the Pond eligible to update the prospect?

            var validationErrors = GetO2ValidationErrors(o2r, o2, cqDto, companyId, UserId);
            if (validationErrors.Any())
            {
                return ProcessValidationErrors(request, validationErrors, key);
            }
            //  no validation errors...
            o2r.Save(o2);
            UpdatePondHealthStatusByLevel(o2.PondId, o2.O2Level);
            cqDto.Key = key;
            return request.CreateResponse(HttpStatusCode.Accepted, cqDto);
        }
コード例 #3
0
        public HttpResponseMessage PondO2ByDate([FromBody] O2ReadingDTO uDto)
        {
            string key;
            var ur = new AppUserRepository();
            var companyId = 0;
            var UserId = ur.ValidateUser(uDto.Key, out key, ref companyId);
            //string dayperiod;
            //if (DateTime.Parse(uDto.ReadingDate).Hour < 12)
            //{
            //    dayperiod = DateTime.Parse(uDto.ReadingDate).AddDays(-1).ToShortDateString();
            //}
            //else
            //{
            //    dayperiod = DateTime.Parse(uDto.ReadingDate).ToShortDateString();
            //}
            //uDto.DayPeriod = dayperiod;

            AppUserRoleRepository aur = new AppUserRoleRepository();

            if (UserId > 0 && aur.IsInRole(UserId, "Airtime"))
            {
                var O2r = new O2ReadingRepository();
                var u = new O2Reading();
                //var predicate = O2r.GetPredicate(uDto, u, companyId);
                var data = O2r.GetPondO2ReadingsByDate(int.Parse(uDto.PondId), DateTime.Parse(uDto.ReadingDate));
                var col = new Collection<Dictionary<string, string>>();

                foreach (var item in data)
                {

                    var dic = new Dictionary<string, string>();

                    dic.Add("PondId", item.PondId.ToString());
                    dic.Add("ReadingId", item.ReadingId.ToString());
                    dic.Add("ReadingDate", item.ReadingDate.ToString());
                    dic.Add("O2Level", item.O2Level.ToString());
                    dic.Add("StaticCount", item.StaticCount.ToString());
                    dic.Add("PortableCount", item.PortableCount.ToString());
                    dic.Add("Note", item.Note);
                    dic.Add("PondStatus", item.Pond.HealthStatus.ToString());
                    col.Add(dic);

                }

                var retVal = new GenericDTO
                {
                    Key = key,
                    ReturnData = col
                };
                return Request.CreateResponse(HttpStatusCode.OK, retVal);
            }
            var message = "validation failed";
            return Request.CreateResponse(HttpStatusCode.NotFound, message);
        }
コード例 #4
0
        private List<DbValidationError> GetO2ValidationErrors(O2ReadingRepository pr, O2Reading contact, O2ReadingDTO cqDto, int companyId, int PondId)
        {
            contact.ProcessRecord(cqDto);

            return pr.Validate(contact);
        }
コード例 #5
0
        public HttpResponseMessage GetLastPondReading([FromBody] O2ReadingDTO uDto)
        {
            string key;
            var ur = new AppUserRepository();
            var companyId = 0;
            var UserId = ur.ValidateUser(uDto.Key, out key, ref companyId);

            AppUserRoleRepository aur = new AppUserRoleRepository();

            if (UserId > 0 && aur.IsInRole(UserId, "Airtime"))
            {
                var O2r = new O2ReadingRepository();
                var u = new O2Reading();
                //var predicate = O2r.GetPredicate(uDto, u, companyId);
                var data = O2r.GetLastPondReadingByPond(int.Parse(uDto.PondId));
                var col = new Collection<Dictionary<string, string>>();

                    var dic = new Dictionary<string, string>();

                    dic.Add("PondId", data.PondId.ToString());
                    dic.Add("ReadingId", data.ReadingId.ToString());
                    dic.Add("ReadingDate", data.ReadingDate.ToString());
                    dic.Add("O2Level", data.O2Level.ToString());
                    dic.Add("StaticCount", data.StaticCount.ToString());
                    dic.Add("PortableCount", data.PortableCount.ToString());
                    dic.Add("Note", data.Note);
                    col.Add(dic);

                var retVal = new GenericDTO
                {
                    Key = key,
                    ReturnData = col
                };
                return Request.CreateResponse(HttpStatusCode.OK, retVal);
            }
            var message = "validation failed";
            return Request.CreateResponse(HttpStatusCode.NotFound, message);
        }