示例#1
0
        public virtual async Task <NotificationResult> InsertAsync(InsertRecipeCommand command)
        {
            var result = new NotificationResult();
            var item   = new RecipeInfo(command);

            result.Add(item.GetNotificationResult());
            if (!result.IsValid)
            {
                return(result);
            }
            result.Add(await _recipeRepository.InsertAsync(item));

            if (result.IsValid)
            {
                if (command.RecipeIngredients != null && command.RecipeIngredients.Count > 0)
                {
                    foreach (var recipeIngredientCommand in command.RecipeIngredients)
                    {
                        var recipeIngredient = new RecipeIngredientInfo(recipeIngredientCommand);
                        recipeIngredient.SetRecipeId(item.Id.Value);
                        result.Add(await _recipeIngredientRepository.InsertAsync(recipeIngredient));
                    }
                }

                result.Data = item.Id;
                result.AddMessage(Shared.Domain.Resources.Handler.InsertSuccess_Message);
            }
            else
            {
                result.AddErrorOnTop(Shared.Domain.Resources.Handler.InsertError_Message);
            }
            return(result);
        }
示例#2
0
        public static decimal Calculate(this RecipeIngredientInfo recipeIngredientInfo)
        {
            return((decimal)GetConvertedAmount(
                       recipeIngredientInfo.Unit.UnitName,
                       recipeIngredientInfo.Ingredient.Unit.UnitName,
                       recipeIngredientInfo.IngredientAmount) * recipeIngredientInfo.Ingredient.CostPerUnit * recipeIngredientInfo.Recipe.Servings);

            // test this out
            //return (decimal)GetConvertedAmount(
            //           recipeIngredientInfo.Ingredient.Unit.UnitName,
            //    recipeIngredientInfo.Unit.UnitName,

            //           recipeIngredientInfo.IngredientAmount) * recipeIngredientInfo.Ingredient.CostPerUnit * recipeIngredientInfo.Recipe.Servings;
        }
        public async Task <NotificationResult> UpdateAsync(RecipeIngredientInfo item)
        {
            var result = new NotificationResult();

            try
            {
                _context.Attach(item);
                _context.Entry(item).State = EntityState.Modified;
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                result.AddError(ex);
            }

            return(result);
        }
        public async Task <NotificationResult> InsertAsync(RecipeIngredientInfo item)
        {
            var result = new NotificationResult();

            try
            {
                await _context.AddAsync(item);

                item.SetId(_context.SaveChanges());
            }
            catch (Exception ex)
            {
                result.AddError(ex);
            }

            return(result);
        }
        public virtual async Task <NotificationResult> UpdateAsync(UpdateRecipeIngredientCommand command)
        {
            var result = new NotificationResult();
            var item   = new RecipeIngredientInfo(command);

            result.Add(item.GetNotificationResult());
            if (!result.IsValid)
            {
                return(result);
            }
            result.Add(await _recipeIngredientRepository.UpdateAsync(item));
            if (result.IsValid)
            {
                result.Data = item.Id;
                result.AddMessage(Shared.Domain.Resources.Handler.UpdateSuccess_Message);
            }
            else
            {
                result.AddErrorOnTop(Shared.Domain.Resources.Handler.UpdateError_Message);
            }

            return(result);
        }
 public static void InsertOrUpdateScopeValidate(this RecipeIngredientInfo item)
 {
     new NotificationContract <RecipeIngredientInfo>(item)
     ;
 }