Пример #1
0
        public Boolean SetClientRating(int clientId, int insertByUserId, int value, string comments = "")
        {
            if (clientId <= 0)
            {
                throw new ArgumentNullException("clientId", "ClientId is null");
            }

            if (insertByUserId <= 0)
            {
                throw new ArgumentNullException("insertByUserId", "InsertByUserId is null");
            }

            if (value < 0 && value > 5)
            {
                throw new ArgumentOutOfRangeException("value", value, "Value min 0 and max 5");
            }

            using (Petz_dbEntities db = new Petz_dbEntities())
            {
                if (db.petz_Rating.Count(x => x.insert_user_id == insertByUserId && x.rating_client_id == clientId) <= 0)
                {
                    petz_Rating rating = new petz_Rating
                    {
                        date_insert      = DateTime.Now,
                        rating_comments  = comments,
                        rating_value     = value,
                        insert_user_id   = insertByUserId,
                        rating_client_id = clientId
                    };
                    db.petz_Rating.Add(rating);
                    db.SaveChanges();

                    var upd = db.petz_Clients.FirstOrDefault(x => x.client_id == clientId);
                    if (upd != null)
                    {
                        upd.client_rating = GetClientRatingValue(clientId);
                        db.SaveChanges();
                    }
                    return(true);
                }
            }
            return(false);
        }
Пример #2
0
        public Boolean SetPetRating(int petId, int insertByUserId, int value, string comments = "")
        {
            if (petId <= 0)
            {
                throw new ArgumentNullException("petId", "PetId is null");
            }

            if (insertByUserId <= 0)
            {
                throw new ArgumentNullException("insertByUserId", "InsertByUserId is null");
            }

            using (Petz_dbEntities db = new Petz_dbEntities())
            {
                if (db.petz_Rating.Count(x => x.insert_user_id == insertByUserId && x.rating_pet_id == petId) <= 0)
                {
                    petz_Rating rating = new petz_Rating
                    {
                        date_insert     = DateTime.Now,
                        rating_comments = comments,
                        rating_value    = value,
                        insert_user_id  = insertByUserId,
                        rating_pet_id   = petId
                    };
                    db.petz_Rating.Add(rating);
                    db.SaveChanges();

                    var upd = db.petz_Pets.FirstOrDefault(x => x.pet_id == petId);
                    if (upd != null)
                    {
                        upd.pet_rating = GetPetRatingValue(petId);
                        db.SaveChanges();
                    }
                    return(true);
                }
                return(false);
            }
        }
Пример #3
0
        public Boolean SetCompanyRating(int companyId, int insertByClientId, int value, string comments = "")
        {
            if (companyId <= 0)
            {
                throw new ArgumentNullException("companyId", "CompanyId is null");
            }

            if (insertByClientId <= 0)
            {
                throw new ArgumentNullException("insertByClientId", "InsertByClientId is null");
            }

            if (value < 0 && value > 5)
            {
                throw new ArgumentOutOfRangeException("value", value, "Value min 0 and max 5");
            }

            using (Petz_dbEntities db = new Petz_dbEntities())
            {
                if (db.petz_Rating.Count(x => x.insert_client_id == insertByClientId && x.rating_company_id == companyId) <= 0)
                {
                    petz_Rating rating = new petz_Rating
                    {
                        date_insert       = DateTime.Now,
                        rating_comments   = comments,
                        rating_value      = value,
                        insert_client_id  = insertByClientId,
                        rating_company_id = companyId
                    };
                    db.petz_Rating.Add(rating);
                    db.SaveChanges();
                    return(true);
                }
                return(false);
            }
        }