コード例 #1
0
        public int CreateNewAuthority(Authority authority)
        {
            using (DobbermanEntities context = new DobbermanEntities())
            {
                // find out if authority already exists by its name
                AuthorityEntity validateAuthority = (from p
                                             in context.Authorities
                                           where p.Name == authority.Name
                                           select p).FirstOrDefault();
                if (!(validateAuthority == null)) return validateAuthority.AuthorityId;

                AuthorityEntity authorityEntity = new AuthorityEntity()
                {
                    Name = authority.Name,
                    CategoryId = authority.CategoryId,
                    FacebookPage = authority.FacebookPage,
                    AccumulatedScore = 0,
                    Score = 50,

                };
                context.AddToAuthorities(authorityEntity);
                context.SaveChanges();
                return authorityEntity.AuthorityId;
            }
        }
コード例 #2
0
        public int CreateNewCategory(Category category)
        {
            using (DobbermanEntities context = new DobbermanEntities())
            {
                // find out if category already exists by its name
                CategoryEntity validateCategory = (from p
                                             in context.Categories
                                                     where p.Name == category.Name
                                                     select p).FirstOrDefault();
                if (!(validateCategory == null)) return validateCategory.CategoryId;

                CategoryEntity categoryEntity = new CategoryEntity()
                {
                    Name = category.Name,
                    Description = category.Description,
                    Picture = category.Picture,

                };
                context.AddToCategories(categoryEntity);
                context.SaveChanges();
                return categoryEntity.CategoryId;
            }
        }
コード例 #3
0
        public int CreateNewReport(Report report)
        {
            ReportEntity reportEntity = new ReportEntity()
            {
                AuthorityId = report.AuthorityId,
                UserId = report.UserId,
                Description = report.Description,
                Date = report.Date,
                Location = report.Location,
                Photo = report.Photo,
                Mood = report.Mood,
            };

            using (DobbermanEntities context = new DobbermanEntities())
            {
                AuthorityEntity reportAuthority = (from p
                                        in context.Authorities
                                                where p.AuthorityId == reportEntity.AuthorityId
                                                select p).FirstOrDefault();
                switch (report.Mood)
                {
                    case "positive":
                        reportAuthority.AccumulatedScore += 100;
                        break;
                    case "concerned":
                        reportAuthority.AccumulatedScore += 50;
                        break;
                    case "negative":
                        //add zero to AccumulatedScore
                        break;
                }
                // change the score of authority to the new weighted score
                reportAuthority.Score = reportAuthority.AccumulatedScore / (reportAuthority.Reports.Count + 1);
                // add new report to the context
                context.AddToReports(reportEntity);
                context.SaveChanges();
            }
            return reportEntity.ReportId;
        }
コード例 #4
0
        public int CreateNewUser(User user)
        {
            using (DobbermanEntities context = new DobbermanEntities())
            {
                // find out if user already exists by its email
                UserEntity validateUser = (from p
                                             in context.Users
                                         where p.Email == user.Email
                                         select p).FirstOrDefault();
                if (!(validateUser == null)) return validateUser.UserId;

                UserEntity userEntity = new UserEntity()
                {
                    Email = user.Email,
                    Name = user.Name,
                };
                context.AddToUsers(userEntity);
                context.SaveChanges();
                return userEntity.UserId;
            }
        }