示例#1
0
文件: Aspect.cs 项目: jjfd/HITRating
        public static Models.Aspect ValidationAndProcess(Models.Aspect data)
        {
            try
            {
                ValidationException validationException = new ValidationException();

                try
                {
                    if (data.CategoryId == null || (data.CategoryId < 1) || (new RestfulModels.Category()).Read((int)data.CategoryId) == null)
                    {
                        validationException.ValidationErrors.Add("产品类别为空");
                    }
                }
                catch
                {
                    validationException.ValidationErrors.Add("产品类别为空");
                }

                if (string.IsNullOrEmpty(data.Title)) {
                    validationException.ValidationErrors.Add("评价内容为空");
                }

                if (data.RatedTimes == null || data.RatedTimes < 0) {
                    data.RatedTimes = 0;
                }

                //created
                if (data.Created == null)
                {
                    data.Created = DateTime.Now;
                }

                if (validationException.ValidationErrors.Count() > 0)
                {
                    throw validationException;
                }
                else
                {
                    return data;
                }
            }
            catch
            {
                throw;
            }
        }
示例#2
0
文件: News.cs 项目: jjfd/HITRating
        public static Models.Review ValidationAndProcess(Models.Review data)
        {
            try
            {
                ValidationException validationException = new ValidationException();

                data.Type = Models.ReviewType.News;
                data.Rate = null;
                data.RatedAspects = null;

                if (data.ProductId != null && (data.ProductId > 0) && (new RestfulModels.Product()).Read((int)data.ProductId) == null)
                {
                    validationException.ValidationErrors.Add("HIT产品为空");
                }

                if (string.IsNullOrEmpty(data.Details))
                {
                    validationException.ValidationErrors.Add("评价内容为空");
                }

                //created
                if (data.Created == null)
                {
                    data.Created = DateTime.Now;
                }

                if (validationException.ValidationErrors.Count() > 0)
                {
                    throw validationException;
                }
                else
                {
                    return data;
                }
            }
            catch
            {
                throw;
            }
        }
示例#3
0
文件: Product.cs 项目: jjfd/HITRating
        public static Models.Product ValidationAndProcess(Models.Product data)
        {
            try
            {
                ValidationException validationException = new ValidationException();

                try
                {
                    if (data.VendorId == null || (data.VendorId < 1) || (new RestfulModels.Vendor()).Read((int)data.VendorId) == null)
                    {
                        validationException.ValidationErrors.Add("供应商为空");
                    }
                }
                catch
                {
                    validationException.ValidationErrors.Add("供应商为空");
                }

                if (string.IsNullOrEmpty(data.Title))
                {
                    validationException.ValidationErrors.Add("名称为空");
                }

                try
                {
                    if (data.CategoryId == null || (data.VendorId < 1) || (new RestfulModels.Category()).Read((int)data.CategoryId) == null)
                    {
                        validationException.ValidationErrors.Add("产品类别不存在");
                    }
                }
                catch
                {
                    validationException.ValidationErrors.Add("产品类别不存在");
                }

                if (string.IsNullOrEmpty(data.Version))
                {
                    validationException.ValidationErrors.Add("版本为空");
                }

                //created
                if (data.Created == null)
                {
                    data.Created = DateTime.Now;
                }

                if (validationException.ValidationErrors.Count() > 0)
                {
                    throw validationException;
                }
                else
                {
                    return data;
                }
            }
            catch
            {
                throw;
            }
        }
示例#4
0
文件: Vote.cs 项目: jjfd/HITRating
        public static Models.Vote ValidationAndProcess(Models.Vote data)
        {
            try
            {
                ValidationException validationException = new ValidationException();

                try
                {
                    if (data.ReviewId == null || (data.ReviewId < 1) || (new RestfulModels.Review()).Read((int)data.ReviewId) == null)
                    {
                        validationException.ValidationErrors.Add("产品评价为空");
                    }
                }
                catch
                {
                    validationException.ValidationErrors.Add("产品评价为空");
                }

                if (data.Supportive != true) {
                    data.Supportive = false;
                }

                //created
                if (data.Created == null)
                {
                    data.Created = DateTime.Now;
                }

                if (validationException.ValidationErrors.Count() > 0)
                {
                    throw validationException;
                }
                else
                {
                    return data;
                }
            }
            catch
            {
                throw;
            }
        }
示例#5
0
文件: Comment.cs 项目: jjfd/HITRating
        public static Models.Comment ValidationAndProcess(Models.Comment data)
        {
            try
            {
                ValidationException validationException = new ValidationException();

                try
                {
                    if (data.ReviewId == null || (data.ReviewId < 1) || (new RestfulModels.Review()).Read((int)data.ReviewId) == null)
                    {
                        validationException.ValidationErrors.Add("产品评价为空");
                    }
                }
                catch
                {
                    validationException.ValidationErrors.Add("产品评价为空");
                }

                //Commenter
                if (string.IsNullOrEmpty(data.Details))
                {
                    validationException.ValidationErrors.Add("评论内容为空");
                }

                //created
                if (data.Created == null)
                {
                    data.Created = DateTime.Now;
                }

                if (validationException.ValidationErrors.Count() > 0)
                {
                    throw validationException;
                }
                else
                {
                    return data;
                }
            }
            catch
            {
                throw;
            }
        }
示例#6
0
        public static Models.Category ValidationAndProcess(Models.Category data)
        {
            try
            {
                ValidationException validationException = new ValidationException();

                //Title
                if (string.IsNullOrEmpty(data.Title))
                {
                    validationException.ValidationErrors.Add("名称为空");
                }

                //created
                if (data.Created == null)
                {
                    data.Created = DateTime.Now;
                }

                if (validationException.ValidationErrors.Count() > 0)
                {
                    throw validationException;
                }
                else
                {
                    return data;
                }
            }
            catch
            {
                throw;
            }
        }
示例#7
0
文件: Rate.cs 项目: jjfd/HITRating
        public static Models.Rate ValidationAndProcess(Models.Rate data)
        {
            try
            {
                ValidationException validationException = new ValidationException();

                try
                {
                    if (data.ReviewId != null && (data.ReviewId > 0) && (new RestfulModels.Review()).Read((int)data.ReviewId) == null)
                    {
                        validationException.ValidationErrors.Add("产品评价不存在");
                    }
                }
                catch
                {
                    validationException.ValidationErrors.Add("产品评价不存在");
                }

                try
                {
                    if (data.AspectId == null || (data.AspectId < 1))
                    {
                        validationException.ValidationErrors.Add("评价问题为空");
                    }
                    else
                    {
                        var aspect = (new RestfulModels.Aspect()).Read((int)data.AspectId);
                        data.AspectTitle = aspect.Title;
                    }
                }
                catch
                {
                    validationException.ValidationErrors.Add("评价问题不存在");
                }

                if (data.Stars < 1 || data.Stars > 5) {
                    validationException.ValidationErrors.Add("评分无效");
                }

                //created
                if (data.Created == null)
                {
                    data.Created = DateTime.Now;
                }

                if (validationException.ValidationErrors.Count() > 0)
                {
                    throw validationException;
                }
                else
                {
                    return data;
                }
            }
            catch
            {
                throw;
            }
        }