protected override RecipeModel EntityToModel(Recipe entity) { Brew entityBrew = entity.Brew; Entities.Resource entityResource = entity.Resource; return(new RecipeModel() { Amount = entity.Amount, Brew = entity.Brew != null ? new BrewModel() { BrewId = entityBrew.BrewId, Description = entityBrew.Description != null ? entityBrew.Description : string.Empty, IsRemoved = entityBrew.IsRemoved, Link = entityBrew.Link != null ? entityBrew.Link : UnitConstants.NotAny, Name = entityBrew.Name, } : null, BrewId = entity.BrewId, Description = entity.Description, Resource = new ResourceModel() { AmountInStock = entityResource.AmountInStock, IsRemoved = entityResource.IsRemoved, Link = entityResource.Link != null ? entityResource.Link : UnitConstants.NotAny, Name = entityResource.Name, ResourceId = entityResource.ResourceId, Unit = entityResource.Unit }, ResourceId = entity.ResourceId }); }
public Resource(Entities.Resource resource, bool includeApp = false) : this(resource) { if (includeApp) { this.Application = new Application(resource.Application); } }
public Resource(Entities.Resource resource) { this.Code = resource.Code; this.Name = resource.Name; this.Description = resource.Description; this.Operations = resource.Operations.ToString(); this.Type = resource.Type; this.TypeCode = resource.Type.AsInt(); this.TypeDescription = resource.Type.GetDescription(); this.InternalCode = resource.InternalCode; }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } List <ImportResourceModel> importedResources; try { importedResources = JsonSerializer.Deserialize <List <ImportResourceModel> >(Json); } catch { ModelState.AddModelError("Json", "Error reading JSON."); return(Page()); } foreach (var resource in importedResources) { var entity = new Entities.Resource(); entity.Location = resource.Location; entity.Metadata = resource.Metadata; entity.CreateDate = DateTime.UtcNow; _context.AddResource(entity); } try { await _context.SaveChangesAsync(); TempData["Message"] = $"{importedResources.Count} resource(s) were successfully imported."; return(RedirectToPage("./Index")); } catch { ModelState.AddModelError("Json", "Error saving resources to database."); } return(Page()); }