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 IEnumerable <string> GetAllBinTypes() { using (var context = new ConfigurationToolContext()) { var repository = new BinRepository(context); return(repository.GetAllBinTypes()); } }
public void CreateNewBin(Bin bin) { using (var context = new ConfigurationToolContext()) { var repository = new BinRepository(context); repository.Add(bin); context.SaveChanges(); } OrderObservableList.AddSorted(GlobalListManagementClass.Instance.Bins, bin); }
public void DeleteBin(Bin bin) { using (var context = new ConfigurationToolContext()) { var repository = new BinRepository(context); repository.Delete(bin); context.SaveChanges(); GlobalListManagementClass.Instance.Bins.Remove(bin); } }
//Gets Procescells, Units, Bins & ParameterDefinitions public FactoryConfig GetFactoryConfig() { using (var context = new ConfigurationToolContext()) { var procescellRepository = new ProcessCellRepository(context); var binRepository = new BinRepository(context); var parameterDefinitionRepository = new ParameterDefinitionRepository(context); var OAUnitDefinitionRepository = new OAUnitDefinitionRepository(context); var factoryConfig = new FactoryConfig(); factoryConfig.ParameterDefinitions = parameterDefinitionRepository.GetAll(); factoryConfig.Procescells = procescellRepository.GetAll(); factoryConfig.Bins = binRepository.GetAll(); factoryConfig.OAUnitDefinitions = OAUnitDefinitionRepository.GetAll(); return(factoryConfig); } }
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)); }
private List <DbValidationError> GetBinDisbursementErrors(BinRepository pr, BinDisbursement bd, BinDisbursementDto dto, int companyId, int PondId) { bd.ProcessRecord(dto); return(pr.Validate(bd)); }