Пример #1
0
        private HttpResponseMessage ProcessNewPondRecord(HttpRequestMessage request, PondDTO uDto, string key, int companyId, int UserId)
        {
            var ur   = new PondRepository();
            var Pond = new Pond();

            var validationErrors = GetValidationErrors(ur, Pond, uDto, companyId, UserId);

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

            Pond        = ur.Save(Pond);
            uDto.Key    = key;
            uDto.PondId = Pond.PondId.ToString();
            var response = request.CreateResponse(HttpStatusCode.Created, uDto);

            response.Headers.Location = new Uri(Url.Link("Default", new
            {
                id = Pond.PondId
            }));
            return(response);
        }
Пример #2
0
        public HttpResponseMessage ChangePondFeedStatus([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, "Admin"))
            {
                var Pond   = new Pond();
                var errors = ValidateDtoData(uDto, Pond);
                if (errors.Any())
                {
                    return(ProcessValidationErrors(Request, errors, key));
                }
                var NEPondId = 0;
                if (int.TryParse(uDto.PondId, out NEPondId))
                {
                    //  editing existing Pond record
                    return(ChangePondFeedStatus(Request, uDto, NEPondId, key, companyId, UserId));
                }
                //  no idea what this is
                var msg = "invalid data structure submitted";
                return(Request.CreateResponse(HttpStatusCode.BadRequest, msg));
            }
            var message = "validation failed";

            return(Request.CreateResponse(HttpStatusCode.NotFound, message));
        }
Пример #3
0
        public HttpResponseMessage PondMortalityLast7Mortalities([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      db        = new AppEntities();
                    string   datepart  = startdate.AddDays(i).ToShortDateString();
                    DateTime begindate = DateTime.Parse(datepart);
                    DateTime enddate   = begindate.AddDays(1);
                    var      data      = db.Mortalities.Where(x => x.PondId == ponddata.PondId && x.MortalityDate >= begindate && x.MortalityDate < enddate).FirstOrDefault();
                    if (data != null)
                    {
                        var dic = new Dictionary <string, string>();

                        dic.Add("PondId", data.PondId.ToString());
                        dic.Add("MortalityId", data.MortalityId.ToString());
                        dic.Add("MortalityDate", data.MortalityDate.ToString());
                        dic.Add("MortalityPounds", data.MortalityPounds.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));
        }
Пример #4
0
        private HttpResponseMessage ChangePondFeedStatus(HttpRequestMessage request, PondDTO cqDto, int contactId, string key, int companyId, int UserId)
        {
            var ur   = new PondRepository();
            var Pond = new Pond();

            Pond = ur.GetById(contactId);

            //  no validation errors...
            Pond.NoFeed = bool.Parse(cqDto.NoFeed);
            ur.Save(Pond);
            cqDto.Key = key;
            return(request.CreateResponse(HttpStatusCode.Accepted, cqDto));
        }
Пример #5
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));
        }
Пример #6
0
        private HttpResponseMessage ProcessExistingPondRecord(HttpRequestMessage request, PondDTO cqDto, int contactId, string key, int companyId, int UserId)
        {
            var ur   = new PondRepository();
            var Pond = new Pond();

            Pond = ur.GetById(contactId);
            //  is the Pond eligible to update the prospect?

            var validationErrors = GetValidationErrors(ur, Pond, cqDto, companyId, UserId);

            if (validationErrors.Any())
            {
                return(ProcessValidationErrors(request, validationErrors, key));
            }
            //  no validation errors...
            ur.Save(Pond);
            cqDto.Key = key;
            return(request.CreateResponse(HttpStatusCode.Accepted, cqDto));
        }
Пример #7
0
 public HttpResponseMessage PondDetail([FromBody] PondDTO cqDTO)
 {
     return(Ponds(Request, cqDTO));
 }
Пример #8
0
        internal HttpResponseMessage Ponds(HttpRequestMessage request, PondDTO cqDTO)
        {
            string key;
            var    aur                 = new AppUserRepository();
            var    companyId           = 0;
            var    UserId              = aur.ValidateUser(cqDTO.Key, out key, ref companyId);
            AppUserRoleRepository aur1 = new AppUserRoleRepository();


            if (UserId > 0 && aur1.IsInRole(UserId, "User"))
            {
                var ur        = new PondRepository();
                var u         = new Pond();
                var predicate = ur.GetPredicate(cqDTO, u, companyId);
                var data      = ur.GetByPredicate(predicate);
                var col       = new Collection <Dictionary <string, string> >();
                var bins      = new Collection <Dictionary <string, string> >();
                if (cqDTO.FarmId != null)
                {
                    var br      = new BinRepository();
                    var binList = br.GetFarmBinList(int.Parse(cqDTO.FarmId));
                    foreach (var bin in binList)
                    {
                        bins.Add(
                            new Dictionary <string, string>()
                        {
                            { "BinID", bin.BinID.ToString() },
                            { "BinName", bin.BinName },
                            { "FarmID", bin.FarmID.HasValue ? bin.FarmID.Value.ToString() : "" },
                            { "CurrentTicket", bin.CurrentTicket.HasValue ? bin.CurrentTicket.Value.ToString() : "" },
                            { "CurrentPounds", bin.CurrentPounds.HasValue ? bin.CurrentPounds.Value.ToString() : "" },
                            { "LastDispersement", bin.LastDisbursement.HasValue ? bin.LastDisbursement.Value.ToShortDateString() : "" },
                            { "LastLoaded", bin.LastLoaded.HasValue ? bin.LastLoaded.Value.ToShortDateString() : "" }
                        }
                            );
                    }
                }
                var farmCol = new Collection <Tuple <int, int> >();
                foreach (var item in data)
                {
                    var dic = new Dictionary <string, string>();
                    dic.Add("PondId", item.PondId.ToString());
                    dic.Add("PondName", item.PondName);
                    dic.Add("StatusId", item.StatusId.ToString());
                    dic.Add("InnovaName", item.InnovaName != null ? item.InnovaName : "");
                    dic.Add("InnovaCode", item.InnovaCode != null ? item.InnovaCode : "");
                    dic.Add("Size", item.Size.ToString());
                    dic.Add("NoFeed", item.NoFeed.ToString());
                    int poundsfedsinceharvest = 0;
                    if (item.Harvests.OrderByDescending(x => x.HarvestDate).FirstOrDefault() != null)
                    {
                        dic.Add("LastHarvest", item.Harvests.OrderByDescending(x => x.HarvestDate).FirstOrDefault().HarvestDate.ToString());
                        poundsfedsinceharvest = item.Feedings.Where(x => x.FeedDate > item.Harvests.OrderByDescending(y => y.HarvestDate).FirstOrDefault().HarvestDate).Sum(x => x.PoundsFed);
                    }
                    else
                    {
                        dic.Add("LastHarvest", "");
                        poundsfedsinceharvest = item.Feedings.Sum(x => x.PoundsFed);
                    }
                    int salepounds = poundsfedsinceharvest / 2;
                    dic.Add("PoundsFedSinceHarvest", poundsfedsinceharvest.ToString());
                    dic.Add("SalesPoundsSinceHarvest", salepounds.ToString());
                    dic.Add("HealthStatus", item.HealthStatus.ToString());
                    col.Add(dic);
                }

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

            return(request.CreateResponse(HttpStatusCode.NotFound, message));
        }
Пример #9
0
        private List <DbValidationError> GetValidationErrors(PondRepository pr, Pond contact, PondDTO cqDto, int companyId, int PondId)
        {
            contact.ProcessRecord(cqDto);

            return(pr.Validate(contact));
        }