private HttpResponseMessage ProcessExistingFeedRecord(HttpRequestMessage request, FeedingDTO cqDto, int contactId, string key, int companyId, int UserId) { var o2r = new FeedingRepository(); var o2 = new Feeding(); o2 = o2r.GetById(contactId); // is the Pond eligible to update the prospect? var validationErrors = GetFeedValidationErrors(o2r, o2, cqDto, companyId, UserId); if (validationErrors.Any()) { return(ProcessValidationErrors(request, validationErrors, key)); } // no validation errors... var binDisb = o2r.GetBinDisbursement(o2.FeedingId); if (binDisb != null) { // there is a BinDisbursement record which has to be modified binDisb.Pounds = o2.PoundsFed; binDisb.UserID = UserId; o2r.SaveChanges(); var br = new BinRepository(); br.UpdateBinCurrentPounds(null, binDisb); } else { // there is no BinDisbursement record to mofify o2r.SaveChanges(); } cqDto.Key = key; return(request.CreateResponse(HttpStatusCode.Accepted, cqDto)); }
private HttpResponseMessage ProcessNewFeedRecord(HttpRequestMessage request, FeedingDTO uDto, string key, int companyId, int UserId) { var ur = new FeedingRepository(); var o2 = new Feeding(); var validationErrors = GetFeedValidationErrors(ur, o2, uDto, companyId, UserId); if (validationErrors.Any()) { return(ProcessValidationErrors(request, validationErrors, key)); } // no validation errors... //Pond.CompanyId = companyId; o2 = ur.Save(o2); var farmid = uDto.FarmID; var br = new BinRepository(); var binCount = br.GetFarmBinList(farmid).Count(); if (binCount > 0) { var binDisb = br.GetNewBinDisbursementRecord(); binDisb.DateCreated = DateTime.Now; var disbType = br.GetDisbursementType("Routine Feeding"); var ticketNbr = br.GetLastBinLoadTicketNumber(uDto.BinID.Value); if (ticketNbr == 0) { return(request.CreateErrorResponse(HttpStatusCode.InternalServerError, string.Format("{0}{1}", "There are no Tickets in BinLoads for BinID ", uDto.BinID))); } var dto = new BinDisbursementDto() { BinID = uDto.BinID.Value, TicketNumber = ticketNbr, Pounds = int.Parse(uDto.PoundsFed), Note = "Record created from daily feed disbursement input screen", DisbursementType = disbType, DisbursementDate = DateTime.Now, CreatedDate = DateTime.Now, UserID = UserId, FeedID = o2.FeedingId }; validationErrors = GetBinDisbursementErrors(br, binDisb, dto, companyId, UserId); if (validationErrors.Any()) { return(ProcessValidationErrors(request, validationErrors, key)); } br.SaveChanges(); br.UpdateBinCurrentPounds(null, binDisb); } uDto.Key = key; var response = request.CreateResponse(HttpStatusCode.Created, uDto); response.Headers.Location = new Uri(Url.Link("Default", new { id = o2.FeedingId })); return(response); }
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 FeedById([FromBody] FeedingDTO 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 O2r = new FeedingRepository(); var data = O2r.GetById(int.Parse(uDto.FeedingId)); var col = new Collection <Dictionary <string, string> >(); 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); 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 FarmLast7Feeds([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) { var col = new Collection<Dictionary<string, string>>(); var fr = new FeedingRepository(); var data = fr.GetPondLast7Feedings(ponditem.PondId); foreach (var item in data) { if (item != null) { var dic = new Dictionary<string, string>(); dic.Add("PondId", item.PondId.ToString()); dic.Add("FeedingId", item.FeedingId.ToString()); dic.Add("FeedDate", item.FeedDate.ToString()); dic.Add("PoundsFed", item.PoundsFed.ToString()); col.Add(dic); } } 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 FarmFeedLast7FeedsTotals([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")) { DateTime startdate = DateTime.Parse(uDto.CurrentTime); var fr = new FeedingRepository(); var dates = fr.GetFarmFeedingsLast7Dates(int.Parse(uDto.FarmId)); var col = new Collection<Dictionary<string, string>>(); foreach (Feeding f in dates) { var data = fr.GetFarmFeedingsByDate(int.Parse(uDto.FarmId), f.FeedDate); if (data != null) { var dic = new Dictionary<string, string>(); int totalfeed = data.Sum(x => x.PoundsFed); int totalfeedcount = data.Count(); if (totalfeedcount > 0) { decimal totalacres = data.Sum(x => x.Pond.Size); decimal averagefeed = totalfeed / totalacres; averagefeed = Math.Round(averagefeed, 0); dic.Add("FeedDate", f.FeedDate.ToShortDateString()); dic.Add("TotalPoundsFed", totalfeed.ToString()); dic.Add("TotalFeeds", totalfeedcount.ToString()); dic.Add("AveragePoundsFed", averagefeed.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); }
private HttpResponseMessage ProcessNewFeedRecord(HttpRequestMessage request, FeedingDTO uDto, string key, int companyId, int UserId) { var ur = new FeedingRepository(); var o2 = new Feeding(); var validationErrors = GetFeedValidationErrors(ur, o2, uDto, companyId, UserId); if (validationErrors.Any()) { return ProcessValidationErrors(request, validationErrors, key); } // no validation errors... //Pond.CompanyId = companyId; o2 = ur.Save(o2); uDto.Key = key; var response = request.CreateResponse(HttpStatusCode.Created, uDto); response.Headers.Location = new Uri(Url.Link("Default", new { id = o2.FeedingId })); return response; }
private HttpResponseMessage ProcessExistingFeedRecord(HttpRequestMessage request, FeedingDTO cqDto, int contactId, string key, int companyId, int UserId) { var o2r = new FeedingRepository(); var o2 = new Feeding(); o2 = o2r.GetById(contactId); // is the Pond eligible to update the prospect? var validationErrors = GetFeedValidationErrors(o2r, o2, cqDto, companyId, UserId); if (validationErrors.Any()) { return ProcessValidationErrors(request, validationErrors, key); } // no validation errors... o2r.Save(o2); cqDto.Key = key; return request.CreateResponse(HttpStatusCode.Accepted, cqDto); }
private List<DbValidationError> GetFeedValidationErrors(FeedingRepository pr, Feeding contact, FeedingDTO cqDto, int companyId, int PondId) { contact.ProcessRecord(cqDto); return pr.Validate(contact); }
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); }
public HttpResponseMessage FeedById([FromBody] FeedingDTO 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 O2r = new FeedingRepository(); var data = O2r.GetById(int.Parse(uDto.FeedingId)); var col = new Collection<Dictionary<string, string>>(); 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); 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 FeedingController() { feedingRepository = new FeedingRepository(); }
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)); }
private List <DbValidationError> GetFeedValidationErrors(FeedingRepository pr, Feeding contact, FeedingDTO cqDto, int companyId, int PondId) { contact.ProcessRecord(cqDto); return(pr.Validate(contact)); }