Example #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);
        }
Example #2
0
        private void UpdatePondHealthStatusByLevel(int pondid, decimal o2level)
        {
            var ur   = new PondRepository();
            var Pond = new Pond();

            Pond = ur.GetById(pondid);
            var or = new O2ReadingRepository();
            List <O2Reading> last2 = or.GetLast2PondReadingsByPond(pondid);


            if (o2level < (decimal)(2.5))
            {
                Pond.HealthStatus = 3;
            }
            else if (last2.Count == 2)
            {
                decimal readingnow  = last2.OrderByDescending(x => x.ReadingId).FirstOrDefault().O2Level;
                decimal readinglast = last2.OrderBy(x => x.ReadingId).FirstOrDefault().O2Level;
                if (readingnow / readinglast <= (decimal).5)
                {
                    Pond.HealthStatus = 2;
                }
                else
                {
                    Pond.HealthStatus = 1;
                }
            }
            else
            {
                Pond.HealthStatus = 1;
            }
            //  no validation errors...
            ur.Save(Pond);
        }
Example #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));
        }
Example #4
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));
        }
Example #5
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));
        }
        public HttpResponseMessage FarmO2Last7Days([FromBody] FarmDTO 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 pr = new PondRepository();
                var ponddata = pr.GetActivePondsForO2(int.Parse(uDto.FarmId));
                DateTime startdate = DateTime.Parse(uDto.CurrentTime);
                var pondcol = new Dictionary<string, Dictionary<string, Collection<Dictionary<string, string>>>>();
                foreach (Pond ponditem in ponddata)
                {
                    var datecol = new Dictionary<string, Collection<Dictionary<string, string>>>();

                        var O2r = new O2ReadingRepository();
                        var data = O2r.GetPondO2Readings7Days(ponditem.PondId, startdate);
                        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());

                            col.Add(dic);

                        }
                        datecol.Add(startdate.ToShortDateString(), col);

                    pondcol.Add(ponditem.PondId.ToString(), datecol);
                }

                var retVal = new FarmO2DTO
                {
                    Key = key,
                    ReturnData = pondcol
                };
                return Request.CreateResponse(HttpStatusCode.OK, retVal);
            }
            var message = "validation failed";
            return Request.CreateResponse(HttpStatusCode.NotFound, message);
        }
        private void UpdatePondHealthStatusByLevel(int pondid, decimal o2level)
        {
            var ur = new PondRepository();
            var Pond = new Pond();
            Pond = ur.GetById(pondid);
            var or = new O2ReadingRepository();
            List<O2Reading> last2 = or.GetLast2PondReadingsByPond(pondid);

            if (o2level < (decimal)(2.5))
            {
                Pond.HealthStatus = 3;
            }
            else if (last2.Count == 2)
            {

                decimal readingnow = last2.OrderByDescending(x => x.ReadingId).FirstOrDefault().O2Level;
                decimal readinglast = last2.OrderBy(x => x.ReadingId).FirstOrDefault().O2Level;
                if (readingnow / readinglast <= (decimal).5)
                {

                    Pond.HealthStatus = 2;
                }
                else
                {
                    Pond.HealthStatus = 1;

                }
            }
            else
            {
                Pond.HealthStatus = 1;
            }
            //  no validation errors...
            ur.Save(Pond);
        }
        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;
        }
        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);
        }
        private List<DbValidationError> GetO2ValidationErrors(O2ReadingRepository pr, O2Reading contact, O2ReadingDTO cqDto, int companyId, int PondId)
        {
            contact.ProcessRecord(cqDto);

            return pr.Validate(contact);
        }
        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);
        }
        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);
        }
Example #13
0
        private List <DbValidationError> GetO2ValidationErrors(O2ReadingRepository pr, O2Reading contact, O2ReadingDTO cqDto, int companyId, int PondId)
        {
            contact.ProcessRecord(cqDto);

            return(pr.Validate(contact));
        }