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); }
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)); }
public HttpResponseMessage O2AddOrEdit([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 thisuser = ur.GetById(UserId); var pr = new PondRepository(); int thisfarm = pr.GetById(int.Parse(uDto.PondId)).FarmId; int UsersFarmId = thisuser.UserFarms.Where(x => x.FarmId == thisfarm).SingleOrDefault().UserFarmId; uDto.UsersFarmId = UsersFarmId.ToString(); 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; var Pond = new Pond(); var errors = ValidateDtoData(uDto, Pond); if (errors.Any()) { return(ProcessValidationErrors(Request, errors, key)); } var NEReadingId = 0; if (int.TryParse(uDto.ReadingId, out NEReadingId)) { if (NEReadingId == -1) { // creating new Pond record return(ProcessNewO2Record(Request, uDto, key, companyId, UserId)); } else { // editing existing Pond record return(ProcessExistingO2Record(Request, uDto, NEReadingId, 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)); }
private HttpResponseMessage ChangePondHealthStatus(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.HealthStatus = int.Parse(cqDto.HealthStatus); ur.Save(Pond); cqDto.Key = key; return(request.CreateResponse(HttpStatusCode.Accepted, cqDto)); }
public HttpResponseMessage FeedAddOrEdit([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 thisuser = ur.GetById(UserId); var pr = new PondRepository(); int thisfarm = pr.GetById(int.Parse(uDto.PondId)).FarmId; int UsersFarmId = thisuser.UserFarms.Where(x => x.FarmId == thisfarm).SingleOrDefault().UserFarmId; uDto.UsersFarmId = UsersFarmId.ToString(); uDto.FarmID = thisfarm; var feed = new Feeding(); var errors = ValidateDtoData(uDto, feed); if (errors.Any()) { return(ProcessValidationErrors(Request, errors, key)); } var NEFeedingId = 0; if (int.TryParse(uDto.FeedingId, out NEFeedingId)) { if (NEFeedingId == -1) { // creating new Feeding record return(ProcessNewFeedRecord(Request, uDto, key, companyId, UserId)); } else { // editing existing Feeding record return(ProcessExistingFeedRecord(Request, uDto, NEFeedingId, 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)); }
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 FeedAddOrEdit([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 thisuser = ur.GetById(UserId); var pr = new PondRepository(); int thisfarm = pr.GetById(int.Parse(uDto.PondId)).FarmId; int UsersFarmId = thisuser.UserFarms.Where(x => x.FarmId == thisfarm).SingleOrDefault().UserFarmId; uDto.UsersFarmId = UsersFarmId.ToString(); var feed = new Feeding(); var errors = ValidateDtoData(uDto, feed); if (errors.Any()) { return ProcessValidationErrors(Request, errors, key); } var NEFeedingId = 0; if (int.TryParse(uDto.FeedingId, out NEFeedingId)) { if (NEFeedingId == -1) { // creating new Pond record return ProcessNewFeedRecord(Request, uDto, key, companyId, UserId); } else { // editing existing Pond record return ProcessExistingFeedRecord(Request, uDto, NEFeedingId, 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); }
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)); }
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 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); }
private HttpResponseMessage ChangePondStatus(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.StatusId = int.Parse(cqDto.StatusId); ur.Save(Pond); cqDto.Key = key; return request.CreateResponse(HttpStatusCode.Accepted, cqDto); }
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 MortalityAddOrEdit([FromBody] MortalityDTO 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 thisuser = ur.GetById(UserId); var pr = new PondRepository(); int thisfarm = pr.GetById(int.Parse(uDto.PondId)).FarmId; int UsersFarmId = thisuser.UserFarms.Where(x => x.FarmId == thisfarm).SingleOrDefault().UserFarmId; uDto.UsersFarmId = UsersFarmId.ToString(); uDto.FarmID = thisfarm; var db = new AppEntities(); var NEMortalityId = 0; if (int.TryParse(uDto.MortalityId, out NEMortalityId)) { if (NEMortalityId == -1) { // creating new Feeding record var mort = new Mortality(); mort.MortalityDate = DateTime.Parse(uDto.MortalityDate); mort.MortalityPounds = int.Parse(uDto.MortalityPounds); mort.PondId = int.Parse(uDto.PondId); mort.UsersFarmId = UsersFarmId; db.Mortalities.Add(mort); db.SaveChanges(); uDto.MortalityId = mort.MortalityId.ToString(); uDto.Key = key; var response = Request.CreateResponse(HttpStatusCode.Created, uDto); response.Headers.Location = new Uri(Url.Link("Default", new { id = mort.MortalityId })); return(response); } else { // editing existing Feeding record var mort = db.Mortalities.Find(NEMortalityId); mort.MortalityDate = DateTime.Parse(uDto.MortalityDate); mort.MortalityPounds = int.Parse(uDto.MortalityPounds); mort.PondId = int.Parse(uDto.PondId); mort.UsersFarmId = UsersFarmId; db.SaveChanges(); uDto.Key = key; return(Request.CreateResponse(HttpStatusCode.Accepted, uDto)); } } // 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)); }