public RecipeEditRequest GetRecipe(int materialId, int recipeId) { var material = m_materialRepository.GetMaterialById(materialId).Ensure(); var entity = recipeId < 1 ? null : m_recipes.LoadRecipe(recipeId).Ensure(); var model = new RecipeEditRequest { MaterialId = material.Id, MaterialName = material.Name, Amount = material.NominalAmount, IsActive = true, RecipeName = "Výroba", AmountUnit = material.NominalUnit.Symbol }; if (entity != null) { if (entity.MaterialId != model.MaterialId) { throw new InvalidOperationException("Nelze zmenit material existujici receptury"); } model.Amount = entity.Amount; model.AmountUnit = entity.AmountUnit; model.RecipeId = entity.RecipeId; model.IsActive = entity.IsActive; model.Note = entity.Note; model.RecipeName = entity.RecipeName; model.ProductionPrice = entity.ProductionPrice; model.Items.AddRange(entity.Items); } var mentry = new MaterialEntry() { Amount = model.Amount, UnitName = model.AmountUnit }; model.ProducedAmountText = mentry.ToString(); return(model); }
public RecipeInfoWithItems LoadRecipe(int recipeId) { var entity = m_database.SelectFrom <IRecipe>().Join(r => r.Components).Join(r => r.ProducedMaterial) .Join(r => r.Components.Each().Material) .Where(r => r.ProjectId == m_session.Project.Id && r.Id == recipeId).Execute().FirstOrDefault(); if (entity == null) { return(null); } var model = new RecipeInfoWithItems() { IsActive = entity.DeleteDateTime == null && entity.DeleteUserId == null, MaterialId = entity.ProducedMaterialId, MaterialName = entity.ProducedMaterial.Name, RecipeId = entity.Id, RecipeName = entity.RecipeName, Amount = entity.RecipeProducedAmount, ProductionPrice = entity.ProductionPricePerUnit ?? 0, AmountUnit = m_unitRepository.GetUnit(entity.ProducedAmountUnitId).Symbol, Note = entity.Note }; foreach (var c in entity.Components.OrderBy(c => c.SortOrder)) { var me = new MaterialEntry() { Amount = c.Amount, MaterialName = c.Material.Name, UnitName = m_unitRepository.GetUnit(c.UnitId).Symbol }; model.Items.Add(new RecipeItem() { IsTransformationSource = c.IsTransformationInput, Text = me.ToString(), IsValid = true }); } return(model); }