private ActionResult Preview() { string raiserID = Request["raiserID"]; var db = new FarmRepository(); var plan = db.GetEntitie <VaccinePlan>(p => p.raiserID == raiserID); if (plan == null) { return(Json(new { success = false }, JsonRequestBehavior.AllowGet)); } var vacc = plan.GetVaccinePlan(); var js = new { success = true, areaName = plan.areaName, raiserName = plan.raiserName, planName = plan.planName, plan = vacc.Where(p => !p.realyInjectionDate.HasValue), planAll = vacc }; return(Json(js, JsonRequestBehavior.AllowGet)); }
public ActionResult Settle(int?id, string a) { if (!id.HasValue) { if (string.IsNullOrEmpty(a)) { return(PartialView("SettleSearch")); } else { return(PartialView("Settle")); } } else { ViewBag.userName = Farm.Authority.Users.Account.userName; FarmRepository rps = new FarmRepository(); var model = rps.GetEntitie <SettledBatch>(p => p.ID == id); if (model == null) { model = new SettledBatch(); } return(View("SettleDetails", model)); } }
private ActionResult Statistics() { FarmRepository rps = new FarmRepository(); var model = base.Entities <Pact, IFarmTable>(rps); return(PartialView("Statistics", model)); }
public void Setup() { _farms = new List <FarmEntity> { new FarmEntity { AmountOfAnimals = Faker.NumberFaker.Number(0, 100), DelitingDate = null, Id = Faker.NumberFaker.Number(0, 100), IsDelete = false, Name = Faker.CompanyFaker.Name(), OwnerName = Faker.NameFaker.MaleName() } }; var mockedDbContext = new Mock <FarmContext>(); mockedDbContext.Setup(x => x.FarmEntities) .Returns(() => new FakeDbSet <FarmEntity>(_farms)); _unitOfWork = new UnitOfWork(mockedDbContext.Object); _farmRepository = new FarmRepository(mockedDbContext.Object); }
public async Task BeginAsync(bool forceUpdate = false) { var importedFarms = await FarmDataService.GetFarmDataAsync(); var dbFarms = await FarmRepository.ListAllAsync(); Logger.LogInformation($"Found {importedFarms.Count} farms in data service and {dbFarms.Count} farms in the database"); foreach (var importedFarm in importedFarms) { var dbFarm = dbFarms.FirstOrDefault(f => f.Name == importedFarm.Name); if (dbFarm == null) { await CreateFarmAsync(importedFarm); } else { await UpdateFarmAsync(importedFarm, dbFarm, forceUpdate); } } foreach (var dbFarm in dbFarms.Where(f => !importedFarms.Any(i => i.Name == f.Name))) { await DeleteFarmAsync(dbFarm); } }
private HttpResponseMessage AddUserFarm(HttpRequestMessage request, UserFarmDTO cqDto, int contactId, string key, int companyId, int userId) { var aur = new UserFarmRepository(); var ur = new UserFarm(); //ur = aur.GetByUserFarmIds(contactId, int.Parse(cqDto.FarmID)); if (cqDto.FarmID == "0") { var fr = new FarmRepository(); foreach (Farm f in fr.GetFarms()) { ur.FarmId = f.FarmId; ur.UserId = contactId; ur.StatusId = 1; aur.Save(ur); } } else { ur.FarmId = int.Parse(cqDto.FarmID); ur.UserId = contactId; ur.StatusId = 1; aur.Save(ur); } cqDto.Key = key; return(request.CreateResponse(HttpStatusCode.Accepted, cqDto)); }
public ActionResult List(FormCollection fc) { var db = new FarmRepository(); var source = db.GetEntities <VaccineTask>(p => p.injectDate < new DateTime(2050, 12, 31)); return(base.DataGrid(source)); //return base.DataGrid<VaccineTask,IFarmTable>(new FarmRepository()); }
public UnitOfWork(ApplicationDbContext context) { _context = context; Farms = new FarmRepository(context); UserFarms = new UserFarmRepository(context); Cattle = new CowRepository(context); Events = new EventRepository(context); CowEvents = new CowEventRepository(context); Relationships = new RelationshipRepository(context); }
public ActionResult ClosurePig(string t) { if (t == "ClosurePigStatistics") { FarmRepository rps = new FarmRepository(); var model = base.Entities <ClosurePig, IFarmTable>(rps); return(PartialView("ClosurePigStatistics", model)); } return(PartialView("ClosurePig")); }
//清栏超过2天没领料的养户 public async Task <ActionResult> FeedOverTimeAsync(string view) { var reslut = await Task.Factory.StartNew(() => { var db = new FarmRepository(); var model = db.GetEntities <LivePig>(p => p.feedSurplusDays < -2); return(model); }); return(PartialView(reslut)); }
//成活率低于90%的养户 public async Task <ActionResult> LiveRateShortAsync(string view) { var reslut = await Task.Factory.StartNew(() => { var db = new FarmRepository(); var model = db.GetEntities <LivePig>(p => p.liveRate < (decimal)0.9); return(model); }); return(PartialView(reslut)); }
public void SetUp() { _mockFarms = new Mock <DbSet <Farm> >(); _mockUserFarms = new Mock <DbSet <UserFarm> >(); var mockContext = new Mock <IApplicationDbContext>(); mockContext.SetupGet(c => c.Farms).Returns(_mockFarms.Object); mockContext.SetupGet(c => c.UserFarms).Returns(_mockUserFarms.Object); _repository = new FarmRepository(mockContext.Object); }
//清栏超过25天的批次 public async Task <ActionResult> CloseOverTimeAsync(string view) { var reslut = await Task.Factory.StartNew(() => { var db = new FarmRepository(); var model = db.GetEntities <ClosurePig>(p => p.closeDate < DateTime.Today.AddDays(-25)); return(model); }); return(PartialView(reslut)); }
private ActionResult FeedPreview() { string raiserID = Request["raiserID"]; var pig = new FarmRepository().GetEntitie <LivePig>(p => p.raiserID == raiserID); if (pig == null) { return(Json(new { success = false, message = string.Format("养户编号 \"{0}\" 没有对应的在养批次", raiserID) }, JsonRequestBehavior.AllowGet)); } string addDays = Request["addDays"]; string delayDays = Request["delayDays"]; int n2, n3; if (!Int32.TryParse(addDays, out n2)) { n2 = pig.GetLastGrantFeedDays(); } if (!Int32.TryParse(delayDays, out n3)) { n3 = pig.feedSurplusDays < 0 ? 0 - pig.feedSurplusDays : 0; } int n1 = pig.feedGrantToDays + 1; //int n2 = addDays.HasValue ? addDays.Value : pig.GetLastGrantFeedDays(); //int n3 = delayDays.HasValue ? delayDays.Value : (pig.feedSurplusDays < 0 ? 0 - pig.feedSurplusDays : 0); int n4 = pig.extantNum; var f = FeedHelper.GetFeeds(n1, n1 + n2 - 1, n4); var ylts = pig.feedSurplusDays + n2 + n3; var ylrq = DateTime.Today.AddDays(ylts); var model = new { success = true, raiserName = pig.raiserName, areaName = pig.areaName, from = n1, add = n2, delay = n3, num = n4, feeds = f, check = (ylts <= AppGlobal.grantFeedDay), feedinfo = string.Format("可用至{0:d},余料天数{1} ", ylrq, ylts) }; return(Json(model, JsonRequestBehavior.AllowGet)); }
//签约超过25天的合同 public async Task <ActionResult> PactOverTimeAsync(string view) { var reslut = await Task.Factory.StartNew(() => { var db = new FarmRepository(); var model = db.GetEntities <Pact>(p => p.statusFlag == 0 && p.pactDate < DateTime.Today.AddDays(-25)); //return model; return(PartialView(model)); }); //return PartialView(reslut); return(reslut); }
public static List<SelectListItem> GetAuthoryFieldItems(string defValue, bool hasAll = false) { List<SelectListItem> Items = new List<SelectListItem>(); if (hasAll) Items.Add(new SelectListItem { Text = "全部", Value = "" }); var db = new FarmRepository(); foreach (var f in db.GetEntities<Structure>(p => p.typeID == 1)) { Items.Add(new SelectListItem { Text = f.name, Value = f.ID.ToString(), Selected = (f.ID.ToString() == defValue) }); } return Items; }
private async Task CreateFarmAsync(FarmData farmData) { // Require a minimum of a name if (string.IsNullOrWhiteSpace(farmData.Name)) { return; } Logger.LogInformation($"Creating farm \"{farmData.Name}\""); var dbFarm = await FarmDataToFarmService.MakeFarmFromFarmDataAsync(farmData); await FarmRepository.CreateAsync(dbFarm); }
public ActionResult Sort(FormCollection fc) { DynamicQuery <Pig> smodel = new DynamicQuery <Pig>(); smodel.UpdateModel(Request.Form); var dataSource = new FarmRepository().GetEntities <Pig>(smodel.whereExp); ReportModel report = new ReportModel(); report.dataSource = dataSource; report.reportName = Request["sortby"] + ".rdlc"; report.displayName = "成活率排名"; Session["report"] = report; return(JavaScript(JSHelper.ShowSuccess("正在生成报表…"))); }
public static List<SelectListItem> GetAuthoryFieldItems(bool hasAll=false) { List<SelectListItem> Items = new List<SelectListItem>(); if(hasAll) Items.Add(new SelectListItem { Text = "全部", Value = "", Selected = true }); var db = new FarmRepository(); foreach (var f in db.GetEntities<Structure>(p=>p.typeID==1)) { SelectListItem item = new SelectListItem(); item.Text = f.name; item.Value = f.ID.ToString(); Items.Add(item); } return Items; }
private ActionResult Statistics() { FarmRepository rps = new FarmRepository(); var model = base.Entities <GrantFeed, IFarmTable>(rps); if (model.Select(p => p.raiserID).Distinct().Count() == 1) { int pigid = model.OrderByDescending(p => p.referTime).FirstOrDefault().PigID; var pig = rps.GetEntitie <LivePig>(p => p.ID == pigid); if (pig != null) { ViewBag.total = model.Where(p => p.PigID == pigid).ToList().Sum(p => p.GetFeedBagNum()); ViewBag.extantNum = pig.extantNum; ViewBag.liveRate = pig.liveRate; } } return(PartialView("Statistics", model)); }
private async Task UpdateFarmAsync(FarmData farmData, Farm dbFarm, bool forceUpdate) { if (IsDifferent(farmData, dbFarm) || forceUpdate) { // Require a minimum of a name if (string.IsNullOrWhiteSpace(farmData.Name)) { return; } Logger.LogInformation($"Updating farm \"{farmData.Name}\""); var updatedFarm = await FarmDataToFarmService.MakeFarmFromFarmDataAsync(farmData); // Mark it as an update of the existing db record updatedFarm.VersionNumber = dbFarm.VersionNumber; await FarmRepository.UpdateAsync(updatedFarm); } }
public ActionResult FeedReport(int?id, string raiserID) { var db = new FarmRepository(); GrantFeed model = null; if (id.HasValue) { model = db.GetEntitie <GrantFeed>(p => p.ID == id.Value); } else { model = db.GetEntities <GrantFeed>(p => p.raiserID == raiserID).OrderByDescending(p => p.referTime).FirstOrDefault(); } if (model == null) { return(HttpNotFound()); } return(View("GrantReport", model)); }
private HttpResponseMessage ProcessExistingFarmRecord(HttpRequestMessage request, FarmDTO cqDto, int contactId, string key, int companyId, int UserId) { var ur = new FarmRepository(); var Farm = new Farm(); Farm = ur.GetById(contactId); // is the Farm eligible to update the prospect? var validationErrors = GetValidationErrors(ur, Farm, cqDto, companyId, UserId); if (validationErrors.Any()) { return ProcessValidationErrors(request, validationErrors, key); } // no validation errors... ur.Save(Farm); cqDto.Key = key; return request.CreateResponse(HttpStatusCode.Accepted, cqDto); }
private List<DbValidationError> GetValidationErrors(FarmRepository pr, Farm contact, FarmDTO cqDto, int companyId, int FarmId) { contact.ProcessRecord(cqDto); return pr.Validate(contact); }
private HttpResponseMessage ChangeThisFarmStatus(HttpRequestMessage request, FarmDTO cqDto, int contactId, string key, int companyId, int UserId) { var ur = new FarmRepository(); var Farm = new Farm(); Farm = ur.GetById(contactId); Farm.StatusId = int.Parse(cqDto.StatusId); // no validation errors... ur.Save(Farm); cqDto.Key = key; return request.CreateResponse(HttpStatusCode.Accepted, cqDto); }
internal HttpResponseMessage Farms(HttpRequestMessage request, FarmDTO 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 FarmRepository(); var u = new Farm(); cqDTO.CompanyId = companyId.ToString(); var predicate = ur.GetPredicate(cqDTO, u, companyId); var data = ur.GetByPredicate(predicate); var col = new Collection<Dictionary<string, string>>(); foreach (var item in data) { var dic = new Dictionary<string, string>(); dic.Add("FarmId", item.FarmId.ToString()); dic.Add("FarmName", item.FarmName); dic.Add("StatusId", item.StatusId.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 ActionResult Settle(FormCollection fn) { FarmRepository rps = new FarmRepository(); return(base.DataGrid <SettledBatch, IFarmTable>(rps)); }
public ActionResult List(FormCollection fc) { FarmRepository rps = new FarmRepository(); return(base.DataGrid <Sales, IFarmTable>(rps)); }
public ActionResult ClosurePig(FormCollection fn) { FarmRepository rps = new FarmRepository(); return(base.DataGrid <ClosurePig, IFarmTable>(rps)); }
private async Task DeleteFarmAsync(Farm dbFarm) { Logger.LogInformation($"Deleting farm \"{dbFarm.Name}\""); await FarmRepository.DeleteAsync(dbFarm); }
public ActionResult Details() { FarmRepository rps = new FarmRepository(); return(base.Entity <Checkout, IFarmTable>(rps)); }
private HttpResponseMessage ProcessNewFarmRecord(HttpRequestMessage request, FarmDTO uDto, string key, int companyId, int UserId) { var ur = new FarmRepository(); var Farm = new Farm(); bool newfromsetup; if (uDto.CompanyId == null) { uDto.CompanyId = companyId.ToString(); newfromsetup = false; } else { newfromsetup = true; } var validationErrors = GetValidationErrors(ur, Farm, uDto, companyId, UserId); if (validationErrors.Any()) { return ProcessValidationErrors(request, validationErrors, key); } // no validation errors... //Farm.CompanyId = companyId; Farm = ur.Save(Farm); if (newfromsetup) { var aur = new AppUserRepository(); var users = aur.GetByCompanyId(Farm.CompanyId); foreach (User user in users) { var ufr = new UserFarmRepository(); var ufarm = new UserFarm(); //ur = aur.GetByUserAndRoleIds(contactId, int.Parse(cqDto.RoleID)); ufarm.UserId = user.UserId; ufarm.FarmId= Farm.FarmId; ufarm.StatusId = 1; ufr.Save(ufarm); } } uDto.Key = key; uDto.FarmId = Farm.FarmId.ToString(); var response = request.CreateResponse(HttpStatusCode.Created, uDto); response.Headers.Location = new Uri(Url.Link("Default", new { id = Farm.FarmId })); return response; }
private HttpResponseMessage AddUserFarm(HttpRequestMessage request, UserFarmDTO cqDto, int contactId, string key, int companyId, int userId) { var aur = new UserFarmRepository(); var ur = new UserFarm(); //ur = aur.GetByUserFarmIds(contactId, int.Parse(cqDto.FarmID)); if (cqDto.FarmID == "0") { var fr = new FarmRepository(); foreach (Farm f in fr.GetFarms()) { ur.FarmId = f.FarmId; ur.UserId = contactId; ur.StatusId = 1; aur.Save(ur); } } else { ur.FarmId = int.Parse(cqDto.FarmID); ur.UserId = contactId; ur.StatusId = 1; aur.Save(ur); } cqDto.Key = key; return request.CreateResponse(HttpStatusCode.Accepted, cqDto); }
public void Setup() { _farms = new List <FarmEntity> { new FarmEntity { AmountOfAnimals = 15, DelitingDate = null, Id = 1, IsDelete = false, Name = Faker.CompanyFaker.Name(), OwnerName = Faker.NameFaker.MaleName(), Cost = 1500 }, new FarmEntity { AmountOfAnimals = 20, DelitingDate = null, Id = 2, IsDelete = false, Name = Faker.CompanyFaker.Name(), OwnerName = Faker.NameFaker.MaleName(), Cost = 400 }, new FarmEntity { AmountOfAnimals = 1, DelitingDate = null, Id = 3, IsDelete = false, Name = Faker.CompanyFaker.Name(), OwnerName = Faker.NameFaker.MaleName(), Cost = 100 }, new FarmEntity { AmountOfAnimals = 100, DelitingDate = null, Id = 4, IsDelete = false, Name = Faker.CompanyFaker.Name(), OwnerName = Faker.NameFaker.MaleName(), Cost = 500 }, new FarmEntity { AmountOfAnimals = 50, DelitingDate = null, Id = 5, IsDelete = false, Name = Faker.CompanyFaker.Name(), OwnerName = Faker.NameFaker.MaleName(), Cost = 500 } }; var mockedDbContext = new Mock <FarmContext>(); _db = mockedDbContext.Object; var dbset = new FakeDbSet <FarmEntity>(_farms); mockedDbContext.Setup(x => x.FarmEntities) .Returns(() => dbset); _unitOfWork = new UnitOfWork(_db); _farmRepository = new FarmRepository(_db); _farmService = new FarmService(_unitOfWork); _farmController = new FarmController(_farmService); }
public HttpResponseMessage FarmsDDLByUserId([FromBody] UtilityDTO utilityDto) { string key; var ur = new AppUserRepository(); var companyId = 0; var userId = ur.ValidateUser(utilityDto.Key, out key, ref companyId); if (userId > 0) { var sr = new FarmRepository(); var data = sr.GetUserFarms(userId); var retVal = new GenericDTO(); retVal.Key = key; var col = new Collection<Dictionary<string, string>>(); foreach (var d in data.Select(farm => new Dictionary<string, string> { {"FarmId", farm.FarmId.ToString()}, {"FarmName", farm.FarmName.ToString() } } ) ) { col.Add(d); } retVal.ReturnData = col; return Request.CreateResponse(HttpStatusCode.OK, retVal); } var message = "validation failed"; return Request.CreateResponse(HttpStatusCode.NotFound, message); }