public bool CreatePlant(PlantViewModel plantModel, ContextModel context) { try { PlantModel plant = new PlantModel { Id = plantModel.Id, Name = plantModel.Name, Address = plantModel.Address, Machines = plantModel.Machines.Select(m => new MachineInfoModel { Id = m.Id }).ToList(), CustomerName = plantModel.CustomerName, LastDateUpdate = DateTime.UtcNow }; _plantManagerService.CreatePlant(plant); return(true); } catch (Exception ex) { if (ex is InvalidOperationException) { return(false); } throw ex; } }
void PlantView_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { foreach (var g in _extGraphs) { ExtGraph.Children.Remove(g); } _extGraphs.Clear(); foreach (var g in _wells) { ExtGraph.Children.Remove(g); } _wells.Clear(); PlantViewModel P = e.NewValue as PlantViewModel; if (P != null) { EnumerableDataSource <Time.Core.TimestampValue> ds = new EnumerableDataSource <TimestampValue>(P.plant.Extractions.AsTimeStamps); ds.SetXMapping(var => dateAxis.ConvertToDouble(var.Time)); ds.SetYMapping(var => var.Value); _extGraphs.Add(ExtGraph.AddLineGraph(ds, new Pen(Brushes.Black, 3), new PenDescription("Groundwater"))); if (P.plant.SurfaceWaterExtrations.Items.Count > 0) { EnumerableDataSource <Time.Core.TimestampValue> ds2 = new EnumerableDataSource <TimestampValue>(P.plant.SurfaceWaterExtrations.AsTimeStamps); ds2.SetXMapping(var => dateAxis.ConvertToDouble(var.Time)); ds2.SetYMapping(var => var.Value); _extGraphs.Add(ExtGraph.AddLineGraph(ds2, new Pen(Brushes.Red, 3), new PenDescription("Surface water"))); } } ZoomToTimeScale(); }
public ActionResult Edit(string id) { PlantViewModel plant = new PlantViewModel(); var result = plant.getPlant(id); return(View(result)); }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Plant plant = _stackpoleContext.Plants.Find(id); if (plant == null) { return(HttpNotFound()); } PlantViewModel plantViewModel = new PlantViewModel(); //plantViewModel.id = plant.id; //plantViewModel.description = plant.description; //plantViewModel.area = plant.area; //plantViewModel.name = plant.name; plantViewModel = ViewModels.Helpers.CreatePlantViewModelFromPlant(plant); plantViewModel.MessageToClient = "You are about to permanently delete this plant"; plantViewModel.ObjectState = ObjectState.Deleted; return(View(plantViewModel)); }
public ActionResult Index() { PlantViewModel plant = new PlantViewModel(); var result = plant.getPlantAPI(); return(View(result)); }
public async Task <ActionResult> Create([Bind(Include = "Code,Name,Location")] PlantViewModel plant) { if (ModelState.IsValid) { var Organization = await db.Organizations.FindAsync(User.GetOrganization()); if (Organization != null) { db.Plants.Add(new Plant { Code = plant.Code, Name = plant.Name, Location = plant.Location, Organization = Organization }); } else { ModelState.AddModelError("Organization", "Unable to retrieve your organization information. Please try again."); } await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(plant)); }
public PlantManagerViewModel GetPlantByMachine(int id) { var result = new PlantManagerViewModel(); var plantModel = _plantManagerService.GetPlantByMachine(id); if (plantModel == null) { return(result); } var plant = new PlantViewModel { Id = plantModel.Id, Name = plantModel.Name, Address = plantModel.Address, CustomerName = plantModel.CustomerName, MachineSerials = plantModel.Machines.Select(u => u.Serial).ToList(), Machines = plantModel.Machines.Select(n => new UserMachineViewModel { Id = n.Id, Serial = n.Serial }).ToList() }; result.Plant = plant; result.Machines = _userManagerViewService.GetMachinesByCustomer(plantModel.CustomerName, false); return(result); }
public void ZoomToTimeScale() { if (SelectionEndTime != DateTime.MinValue) { double xmin = dateAxis.ConvertToDouble(SelectionStartTime); double xlength = dateAxis.ConvertToDouble(SelectionEndTime) - dateAxis.ConvertToDouble(SelectionStartTime); DataRect visible2; ExtGraph.FitToView(); visible2 = new DataRect(xmin, ExtGraph.Visible.Y, xlength, ExtGraph.Visible.Height); PlantViewModel Pm = DataContext as PlantViewModel; //Zoom the extraction graph if (Pm != null && (Pm.plant.Extractions.Items.Count() != 0 | Pm.plant.SurfaceWaterExtrations.Items.Count() != 0)) { var select = Pm.plant.Extractions.Items.Union(Pm.plant.SurfaceWaterExtrations.Items).Where(var => var.StartTime >= SelectionStartTime & var.EndTime <= SelectionEndTime); if (select != null && select.Count() != 0) { double ymin = select.Min(y => y.Value); double yheight = select.Max(y => y.Value) - ymin; ymin = ymin - 0.05 * yheight; yheight *= 1.1; visible2 = new DataRect(xmin, ymin, xlength, yheight); } } ExtGraph.Visible = visible2; } }
// GET: Plants/Create public ActionResult Create() { PlantViewModel plantViewModel = new PlantViewModel(); plantViewModel.ObjectState = ObjectState.Added; return(View(plantViewModel)); }
public async Task <IActionResult> Create([FromBody] PlantViewModel pvm) { try { CurrentUser cUser = new CurrentUser(HttpContext, _configuration); pvm.UserId = cUser.UserId; pvm.ReturnKey = 1; pvm.PlantAreaId = 0; pvm.Active = "Y"; var result = await plantRepo.SaveOrUpdate(pvm); await auditLogService.LogActivity(cUser.UserId, cUser.HostIP, cUser.SessionId, "Plant", "Plant Created."); return(Ok(result)); } catch (CustomException cex) { var returnObj = new EmaintenanceMessage(cex.Message, cex.Type, cex.IsException, cex.Exception?.ToString()); return(StatusCode(StatusCodes.Status500InternalServerError, returnObj)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, new EmaintenanceMessage(ex.Message))); } }
private void ViewSchedule_OnClicked(object sender, RoutedEventArgs e) { PlantViewModel viewModel = (PlantViewModel)DataContext; Pages requestpage = (Pages)Enum.Parse(typeof(Pages), "FullScheduleView"); NavigationEvents.RequestPage(requestpage, viewModel.Plant.Id); }
public IActionResult Edit(PlantViewModel updatedPlant) { if (ModelState.IsValid) { string imageName = SaveAndGenerateImageName(updatedPlant.ImageFile); var existingPlant = _garden.GetPlant(updatedPlant.Id.Value, UserId()); var plant = new Plant() { Id = existingPlant.Id, Name = updatedPlant.Name, Type = updatedPlant.Type, DaysBetweenWatering = updatedPlant.DaysBetweenWatering, DateAdded = existingPlant.DateAdded, Waterings = existingPlant.Waterings, UserId = UserId(), Notes = updatedPlant.Notes, ImageName = imageName == DEFAULT_IMAGE_NAME ? existingPlant.ImageName : imageName }; _garden.UpdatePlant(plant); return(RedirectToAction("Details", new { id = existingPlant.Id })); } else { ViewBag.IsEditing = true; return(View("Form", updatedPlant)); } }
public async Task <IActionResult> GetPlant(int id) { var plantFull = new PlantViewModel(); var plant = _db.Plants.Find(id); if (plant == null) { return(NotFound()); } plantFull.Plant = plant; plantFull.PlantPhotos = _db.Photos.Where(photo => photo.PlantId == id).ToList(); plantFull.Parameters = _db.Parameters.Where(parameter => parameter.PlantId == id).ToList(); plantFull.Offers = _db.Offers.Where(offer => offer.PlantId == id && offer.Company.Confirmed).OrderByDescending(offer => offer.Created).ToList(); foreach (var offer in plantFull.Offers) { offer.Company = _db.Companies.Where(company => company.Id == offer.CompanyId).First(); } ViewBag.Title = plant.Title; var user = await _userManager.GetUserAsync(User); if (user != null) { ViewBag.UserCompaniesCount = _db.Companies.Where(company => company.UserId == user.Id).Count(); } return(View("Index", plantFull)); }
public ActionResult Edit(PlantViewModel plant) { using (HttpClient client = new HttpClient()) { //Connect to server client.BaseAddress = new Uri("http://localhost:61347/"); //Clears old data??? client.DefaultRequestHeaders.Accept.Clear(); PlantViewModel newPlant = new PlantViewModel(); newPlant.Name = plant.Name; newPlant.SoilMoistureMin = plant.SoilMoistureMin; newPlant.SoilMoistureMax = plant.SoilMoistureMax; newPlant.SoilMoistureNow = plant.SoilMoistureNow; newPlant.Category = plant.Category; newPlant.SunlightMin = plant.SunlightMin; newPlant.SunlightMax = plant.SunlightMax; newPlant.SunlightNow = plant.SunlightNow; newPlant.ID_Type = plant.ID_Type; newPlant.StartDate = plant.StartDate; newPlant.Updated = plant.Updated; newPlant.url = plant.url; //Update api var response = client.PutAsync("http://localhost:61347/api/Plant/" + plant.ID, new StringContent( Newtonsoft.Json.JsonConvert.SerializeObject(newPlant), Encoding.UTF8, "application/json")).Result; } return(RedirectToAction("Index")); }
//[HttpGet] //[AuthSecurityFilter(ProjectObject = "Plant", Mode = "R")] public ActionResult MasterPartial(int masterCode) { PlantViewModel plantVM = masterCode == 0 ? new PlantViewModel() : Mapper.Map <Plant, PlantViewModel>(_plantBusiness.GetPlant(masterCode)); plantVM.IsUpdate = masterCode == 0 ? false : true; return(PartialView("_AddPlant", plantVM)); }
public ActionResult Add() { List <Site> sites = _siteService.GetAll(""); PlantViewModel model = new PlantViewModel(); model.Sites = sites.ToArray(); return(View(model)); }
public IActionResult Index() { var ViewModel = new PlantViewModel { plants = _context.Plant.ToList() }; return(View(ViewModel)); }
public ActionResult CheckPlantExist(PlantViewModel plantVM) { bool exists = _plantBusiness.CheckPlantNameExist(Mapper.Map <PlantViewModel, Plant>(plantVM)); if (exists) { return(Json("<p><span style='vertical-align: 2px'>Plant already is in use </span> <i class='fa fa-times' style='font-size:19px; color: red'></i></p>", JsonRequestBehavior.AllowGet)); } return(Json(true, JsonRequestBehavior.AllowGet)); }
public IActionResult Save(PlantViewModel item) { if (ModelState.IsValid) { _service.AddUpdatePlant(item); return(RedirectToAction("Index")); } return(RedirectToAction("Edit")); }
public async Task Update(PlantViewModel model) { if (!ModelState.IsValid) { return; } var plant = await _plantRepository.GetById(model.Id); plant.Name = model.Name; plant.EfaNitrogenRate = model.EfaNitrogenRate; await _plantRepository.Update(plant); }
public IActionResult Quiz() { var ex = new ExhibitModel(); var fishVM = new FishViewModel(); var plantVM = new PlantViewModel(); var trashVM = new TrashViewModel(); ex.Fishes = fishVM.GetFishes(); ex.Plants = plantVM.GetPlants(); ex.Trash = trashVM.GetTrash(); return(View("Quiz", ex)); }
public async Task <IActionResult> ChoosePlants() { var userPlants = LoggedUser.ChoosedPlants; var model = new PlantViewModel() { AvailablePlants = await GetAvailablePlants(), SelectedPlants = userPlants.Select(x => x.Plant.Id.ToString()).ToList(), }; return(View(model)); }
public PlantViewModel GetPlantItem(int id) { var result = _dbContext.Plants.Find(id); var item = new PlantViewModel { Id = result.Id, PlantName = result.PlantName, IsActive = result.IsActive }; return(item); }
public async Task <IActionResult> GetLatinGenus(string genus) { genus = genus.ToLower(); var gen = await _context.Genus.FirstOrDefaultAsync(g => g.LatinName.ToLower() == genus); if (gen == null) { return(NotFound(genus)); } var genusId = gen.Id; var plants = await _context.Plants.Include(p => p.PlantCharacteristics) .Include(p => p.Family) .Where(p => p.GenusId == genusId) .ToListAsync(); var plantViewModels = new List <PlantViewModel>(); foreach (var plant in plants) { var plantViewModel = new PlantViewModel() { Id = plant.Id, CommonName = plant.CommonName, SecondaryName = plant.SecondaryName ?? "", TertiaryName = plant.TertiaryName ?? "", LatinName = plant.LatinName, Family = new PlantsFamilyViewModel() { CommonName = plant.Family.CommonName, LatinName = plant.Family.LatinName } }; foreach (var characteristic in plant.PlantCharacteristics) { var state = await _context.States.Include(s => s.Characteristic) .FirstOrDefaultAsync(s => s.Id == characteristic.StateId); if (plantViewModel.Characteristics.Keys.Any(k => k == state.Code)) { continue; } plantViewModel.Characteristics.Add(state.Code, null); } plantViewModels.Add(plantViewModel); } return(Ok(plantViewModels)); }
// // GET: /Plant/ public ActionResult Index() { var plant = new PlantViewModel { MainMenu = _mainMenu, CurrentMenu = PageInfo, Details = Mapper.Map <List <DetailPlantT1001W> >(_plantBll.GetAllPlant()), IsNotViewer = (CurrentUser.UserRole != Enums.UserRole.Viewer && CurrentUser.UserRole != Enums.UserRole.Controller ? true : false) }; ViewBag.Message = TempData["message"]; return(View("Index", plant)); }
public HttpResponseMessage InsertPlant(PlantViewModel plant) { try { ContextModel context = _contextService.GetContext(); var result = _plantService.CreatePlant(plant, context); return(Request.CreateResponse(HttpStatusCode.OK, result, MediaTypeHeaderValue.Parse("application/json"))); } catch (InvalidOperationException ex) { return(Request.CreateResponse(HttpStatusCode.Conflict, ex, MediaTypeHeaderValue.Parse("application/json"))); } }
public App(string dbPath) { InitializeComponent(); // Load the resource dictionary where we keep all the style definitions if (Application.Current.Resources == null) { Application.Current.Resources = new ResourceDictionary(); } PlantData = new PlantViewModel(dbPath); MainPage = new NavigationPage(new PageTopLevel()); }
public ActionResult UpdatePlant(Plant plant) { try { this._plantService.Update(plant); } catch (Exception ex) { PlantViewModel model = getModelById(plant.Id); model.ErrorMessage = "There is a problem updating Plant.Please try again later."; return(View()); } return(RedirectToAction("List")); }
public ActionResult Delete(PlantViewModel plant) { using (HttpClient client = new HttpClient()) { //Connect to server client.BaseAddress = new Uri("http://localhost:61347/"); //Clears old data??? client.DefaultRequestHeaders.Accept.Clear(); //delete api based on id var response = client.DeleteAsync("http://localhost:61347/api/Plant/" + plant.ID).Result; } return(RedirectToAction("Index")); }
public PlantViewModel getModelById(int id) { Plant data = _plantService.GetPlantById(id); PlantViewModel model = new PlantViewModel(); model.Id = data.Id; model.Name = data.Name; model.Location = data.Location; model.PlantInCharge = data.PlantInCharge; model.SiteId = data.SiteId; model.SiteName = _siteService.getSiteNameById(data.SiteId.Value); model.Sites = _siteService.GetAll("").ToArray(); model.ErrorMessage = ""; return(model); }