/// <summary>
        /// Validate model object before save
        /// </summary>
        /// <param name="creatorUserDb"></param>
        /// <returns></returns>
        private bool Valid(DM.RestaurantReviewEntities db)
        {
            if (string.IsNullOrEmpty(Creator.Username))
            {
                throw new Exception("Creator is required.");
            }

            CreatorUserDb = db.Users.FirstOrDefault(u => u.UserName == Creator.Username);
            if (CreatorUserDb == null)
            {
                throw new Exception("Creator was not found.");
            }

            if (string.IsNullOrEmpty(Name))
            {
                throw new Exception("Restaurant Name is required.");
            }

            if (string.IsNullOrEmpty(City))
            {
                throw new Exception("Restaurant City is required.");
            }

            if (State == null)
            {
                throw new Exception("Restaurant State is required.");
            }

            if (!db.States.Any(s => s.Id == State.Id))
            {
                throw new Exception("Restaurant State was not found.");
            }

            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Validate model object before save
        /// </summary>
        /// <param name="creatorUserDb"></param>
        /// <returns></returns>
        private bool Valid(DM.RestaurantReviewEntities db)
        {
            if (string.IsNullOrEmpty(Reviewer.Username))
            {
                throw new Exception("Reviewer is required.");
            }

            ReviewerUserDb = db.Users.FirstOrDefault(u => u.UserName == Reviewer.Username);
            if (ReviewerUserDb == null)
            {
                throw new Exception("Reviewer was not found.");
            }

            if (Restaurant == null)
            {
                throw new Exception("Restaurant is required.");
            }

            if (!db.Restaurants.Any(r => r.Id == Restaurant.Id))
            {
                throw new Exception("Restaurant was not found.");
            }

            if (string.IsNullOrEmpty(ReviewText))
            {
                throw new Exception("Review is required.");
            }

            return(true);
        }