コード例 #1
0
        /// <summary>
        /// Checks if related entities exitst
        /// </summary>
        /// <param name="model">Technological process model to be validated</param>
        /// <param name="statusMessage">Error handler to which problem will be added</param>
        /// <returns>Status message with validaton information</returns>
        private async Task <IErrorHandler> CheckRelatedEntitiesExists(TechProcess model, IErrorHandler statusMessage)
        {
            // check if related facility exists
            if (await db.Facility.FirstOrDefaultAsync(i => i.Id == model.FacilityId) == null)
            {
                statusMessage.AddProblem(new Problem
                {
                    Entity          = "Facility.",
                    EntityKey       = (model.FacilityId).ToString(),
                    Message         = "Facility with this Id isn't found",
                    RedirectRoute   = FacilitiesRouting.Index,
                    UseKeyWithRoute = false
                });
            }

            // check if related product from catalog exists
            if (await db.Recipe.FirstOrDefaultAsync(i => i.Id == model.RecipeId) == null)
            {
                statusMessage.AddProblem(new Problem
                {
                    Entity          = "Recipe.",
                    EntityKey       = (model.RecipeId).ToString(),
                    Message         = "Recipe with this Id isn't found",
                    RedirectRoute   = RecipesRouting.Index,
                    UseKeyWithRoute = false
                });
            }

            return(statusMessage);
        }
コード例 #2
0
 /// <summary>
 /// Checks if user found by <c>key</c> is current user
 /// </summary>
 /// <param name="statusMessage">Status message to which problem will be added</param>
 /// <param name="key">Login of user to be found</param>
 /// <returns>Status message with validaton information</returns>
 private IErrorHandler CheckIfUserCurrentUser(IErrorHandler statusMessage, object key)
 {
     if (contextAccessor.HttpContext.User.FindFirst(System.Security.Claims.ClaimsIdentity.DefaultNameClaimType)?.Value == (string)key)
     {
         statusMessage.AddProblem(new Problem
         {
             Entity          = "User.",
             EntityKey       = (string)key,
             Message         = "You cannot do this type of actions to your account while still been log in into it.",
             RedirectRoute   = UserManagmentRouting.Index,
             UseKeyWithRoute = false
         });
     }
     return(statusMessage);
 }
コード例 #3
0
 /// <summary>
 /// Checks if related entities exitst
 /// </summary>
 /// <param name="model">Storage model with key properties of related entities</param>
 /// <param name="statusMessage">Error handler to which problem will be added</param>
 /// <returns>Status message with validaton information</returns>
 private async Task <IErrorHandler> CheckRelatedEntitiesExists(Storage model, IErrorHandler statusMessage)
 {
     // check if related company exists
     if (await db.Company.FirstOrDefaultAsync(i => i.Id == model.CompanyId) == null)
     {
         statusMessage.AddProblem(new Problem
         {
             Entity          = "Company.",
             EntityKey       = (model.CompanyId).ToString(),
             Message         = "Company with this Id isn't found",
             RedirectRoute   = CompaniesRouting.Index,
             UseKeyWithRoute = false
         });
     }
     return(statusMessage);
 }
コード例 #4
0
 /// <summary>
 /// Checks if related entities exitst
 /// </summary>
 /// <param name="model">License model with key properties of related entities</param>
 /// <param name="statusMessage">Error handler to which problem will be added</param>
 /// <returns>Status message with validaton information</returns>
 private async Task <IErrorHandler> CheckRelatedEntitiesExists(License model, IErrorHandler statusMessage)
 {
     // check if related product from catalog exists
     if (await db.ProductCatalog.FirstOrDefaultAsync(i => i.Id == model.ProductId) == null)
     {
         statusMessage.AddProblem(new Problem
         {
             Entity          = "Products from catalog.",
             EntityKey       = (model.ProductId).ToString(),
             Message         = "Product with this Id isn't found",
             RedirectRoute   = ProductsCatalogRouting.Index,
             UseKeyWithRoute = false
         });
     }
     return(statusMessage);
 }
コード例 #5
0
        /// <summary>
        /// Checks if tech process not exists
        /// </summary>
        /// <param name="key">RecipeId and FacilityId of tech process to be found</param>
        /// <returns>Status message with validaton information</returns>
        private async Task <IErrorHandler> CheckNotExists(object key, IErrorHandler statusMessage)
        {
            // facility id and recipe id
            var tupleKey = (ValueTuple <int, int>)key;

            // check if tech process exists
            if (await db.TechProcess.FirstOrDefaultAsync(i => i.FacilityId == tupleKey.Item1 &&
                                                         i.RecipeId == tupleKey.Item2) != null)
            {
                statusMessage.AddProblem(new Problem
                {
                    Entity        = $"Technological process. Recipe Id: {tupleKey.Item2}.",
                    EntityKey     = tupleKey.Item1.ToString(),
                    Message       = "Technological process with this Id's is found. Remove it before adding new with same key.",
                    RedirectRoute = FacilityTechProcessesRouting.Index
                });
            }

            return(statusMessage);
        }
コード例 #6
0
        /// <summary>
        /// Checks if role exists
        /// </summary>
        /// <param name="statusMessage">Status message to which problem will be added</param>
        /// <param name="key">Role name to be found</param>
        /// <returns>Status message with validaton information</returns>
        private async Task <IErrorHandler> CheckRoleExists(IErrorHandler statusMessage, object key)
        {
            string roleName = (string)key;

            // check if role exists
            var dbRole = await db.Role.FirstOrDefaultAsync(i => i.Name == roleName);

            if (dbRole == null)
            {
                statusMessage.AddProblem(new Problem
                {
                    Entity          = "User.",
                    EntityKey       = statusMessage.ProblemStatus.EntityKey,
                    Message         = $"Such role: {roleName}, don't exist in DataBase.",
                    RedirectRoute   = UserManagmentRouting.Index,
                    UseKeyWithRoute = false
                });
            }
            return(statusMessage);
        }
コード例 #7
0
        /// <summary>
        /// Validates product to recipe relation model
        /// </summary>
        /// <param name="statusMessage">Error handler to which found problems will be added</param>
        /// <param name="modelState">Model state with validation problems</param>
        /// <returns></returns>
        public IErrorHandler ValidateModel(IErrorHandler statusMessage, ModelStateDictionary modelState)
        {
            if (!modelState.IsValid)
            {
                var errors = modelState.Values.SelectMany(i => i.Errors);

                foreach (var error in errors)
                {
                    statusMessage.AddProblem(new Problem
                    {
                        Entity          = "Recipe product changes.",
                        EntityKey       = "",
                        Message         = error.ErrorMessage,
                        RedirectRoute   = RecipesRouting.Index,
                        UseKeyWithRoute = false
                    });
                }
            }

            return(statusMessage);
        }