Beispiel #1
0
        public HttpResponseMessage PondFeedLast7Days([FromBody] PondDTO 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, "Chowtime"))
            {
                var      pr        = new PondRepository();
                var      ponddata  = pr.GetById(int.Parse(uDto.PondId));
                DateTime startdate = DateTime.Now;

                int i   = 0;
                var col = new Collection <Dictionary <string, string> >();
                while (i > -7)
                {
                    var fr   = new FeedingRepository();
                    var data = fr.GetPondFeedingsByDate(ponddata.PondId, startdate.AddDays(i));
                    if (data != null)
                    {
                        var dic = new Dictionary <string, string>();

                        dic.Add("PondId", data.PondId.ToString());
                        dic.Add("FeedingId", data.FeedingId.ToString());
                        dic.Add("FeedDate", data.FeedDate.ToString());
                        dic.Add("PoundsFed", data.PoundsFed.ToString());
                        col.Add(dic);
                    }

                    i--;
                }
                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 FarmFeedLast7Days([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, "Chowtime"))
            {
                var pr = new PondRepository();
                var ponddata = pr.GetActivePonds(int.Parse(uDto.FarmId));
                DateTime startdate = DateTime.Parse(uDto.CurrentTime);
                var pondcol = new Dictionary<string, Collection<Dictionary<string, string>>>();
                foreach (Pond ponditem in ponddata)
                {
                    int i = 0;
                    var col = new Collection<Dictionary<string, string>>();
                    while (i > -7)
                    {
                        var fr = new FeedingRepository();
                        var data = fr.GetPondFeedingsByDate(ponditem.PondId, startdate.AddDays(i));

                        if (data != null)
                        {
                            var dic = new Dictionary<string, string>();

                            dic.Add("PondId", data.PondId.ToString());
                            dic.Add("FeedingId", data.FeedingId.ToString());
                            dic.Add("FeedDate", data.FeedDate.ToString());
                            dic.Add("PoundsFed", data.PoundsFed.ToString());
                            col.Add(dic);
                        }
                        else
                        {
                            var dic = new Dictionary<string, string>();

                            dic.Add("PondId", ponditem.PondId.ToString());
                            dic.Add("FeedingId", "");
                            dic.Add("FeedDate", startdate.AddDays(i).Date.ToShortDateString());
                            dic.Add("PoundsFed", "0");
                            col.Add(dic);
                        }
                        i--;
                    }
                    pondcol.Add(ponditem.PondId.ToString(), col);
                }

                var retVal = new FarmFeedDTO
                {
                    Key = key,
                    ReturnData = pondcol
                };
                return Request.CreateResponse(HttpStatusCode.OK, retVal);
            }
            var message = "validation failed";
            return Request.CreateResponse(HttpStatusCode.NotFound, message);
        }
        public HttpResponseMessage PondFeedLast7Feeds([FromBody] PondDTO 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, "Chowtime"))
            {
                var pr = new PondRepository();
                var ponddata = pr.GetById(int.Parse(uDto.PondId));
                DateTime startdate = DateTime.Now;

                int i = 0;
                int j = 0;
                int pondDataCount = 0;

                var col = new Collection<Dictionary<string, string>>();
                while (pondDataCount < 7 && j < 10)
                {
                    var fr = new FeedingRepository();
                    var data = fr.GetPondFeedingsByDate(ponddata.PondId, startdate.AddDays(i));
                    if (data != null)
                    {

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

                        dic.Add("PondId", data.PondId.ToString());
                        dic.Add("FeedingId", data.FeedingId.ToString());
                        dic.Add("FeedDate", data.FeedDate.ToString());
                        dic.Add("PoundsFed", data.PoundsFed.ToString());
                        col.Add(dic);
                        pondDataCount++;
                        // reset j - haven't hit null territory yet
                        j = 0;
                    }
                    else { j++; }
                    i--;
                }
                var retVal = new GenericDTO
                {
                    Key = key,
                    ReturnData = col
                };
                return Request.CreateResponse(HttpStatusCode.OK, retVal);
            }
            var message = "validation failed";
            return Request.CreateResponse(HttpStatusCode.NotFound, message);
        }
Beispiel #4
0
        public HttpResponseMessage PondFeedLast7Feeds([FromBody] PondDTO 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, "Chowtime"))
            {
                var      pr        = new PondRepository();
                var      ponddata  = pr.GetById(int.Parse(uDto.PondId));
                DateTime startdate = DateTime.Now;

                int i             = 0;
                int j             = 0;
                int pondDataCount = 0;

                var col = new Collection <Dictionary <string, string> >();
                while (pondDataCount < 7 && j < 10)
                {
                    var fr   = new FeedingRepository();
                    var data = fr.GetPondFeedingsByDate(ponddata.PondId, startdate.AddDays(i));



                    if (data != null)
                    {
                        var      db        = new AppEntities();
                        string   datepart  = data.FeedDate.ToShortDateString();
                        DateTime begindate = DateTime.Parse(datepart);
                        DateTime enddate   = begindate.AddDays(1);
                        var      data2     = db.Mortalities.Where(x => x.PondId == data.PondId && x.MortalityDate >= begindate && x.MortalityDate < enddate).FirstOrDefault();
                        var      dic       = new Dictionary <string, string>();

                        dic.Add("PondId", data.PondId.ToString());
                        dic.Add("FeedingId", data.FeedingId.ToString());
                        dic.Add("FeedDate", data.FeedDate.ToString());
                        dic.Add("PoundsFed", data.PoundsFed.ToString());
                        dic.Add("MortalityId", data2 != null ? data2.MortalityId.ToString() : "");
                        dic.Add("MortalityDate", data2 != null ? data2.MortalityDate.ToString() : "--");
                        dic.Add("MortalityPounds", data2 != null ? data2.MortalityPounds.ToString() : "0");
                        col.Add(dic);
                        pondDataCount++;
                        // reset j - haven't hit null territory yet
                        j = 0;
                    }
                    else
                    {
                        j++;
                    }
                    i--;
                }
                var retVal = new GenericDTO
                {
                    Key        = key,
                    ReturnData = col
                };
                return(Request.CreateResponse(HttpStatusCode.OK, retVal));
            }
            var message = "validation failed";

            return(Request.CreateResponse(HttpStatusCode.NotFound, message));
        }