コード例 #1
0
        public async Task <HealthRequest> AddOrUpdateRequest(HealthRequest healthRequest)
        {
            try
            {
                //If there is no id assigned to the blog
                if (healthRequest.Id == Guid.Empty)
                {
                    //Then we need to add a new record
                    DbContext.HealthRequests.Add(healthRequest);
                }
                else
                {
                    //Get the blokg from the db
                    var healthrequestDb = await DbContext.HealthRequests.SingleOrDefaultAsync(item => item.Id == healthRequest.Id);

                    //Update the wanted values
                    healthrequestDb.Subject = healthRequest.Subject;
                    healthrequestDb.Content = healthRequest.Content;
                    healthrequestDb.Note    = healthRequest.Note;

                    healthRequest = healthrequestDb;
                    //Mark it as modified
                    DbContext.Entry(healthrequestDb).State = EntityState.Modified;
                }

                await DbContext.SaveChangesAsync();

                return(healthRequest);
            }
            catch (System.Exception ex)
            {
                LogginService.LogException(ex);
            }
            return(null);
        }
コード例 #2
0
 public async Task <ExternalLink> GetLink(Guid id)
 {
     try
     {
         return(await DbContext.ExternalLinks.SingleOrDefaultAsync(item => item.Id == id));
     }
     catch (Exception ex)
     {
         LogginService.LogException(ex);
     }
     return(null);
 }
 public async Task <IEnumerable <Tennis> > GetTennisRecords()
 {
     try
     {
         return(await DbContext.Tennis.ToListAsync());
     }
     catch (System.Exception ex)
     {
         LogginService.LogException(ex);
     }
     return(null);
 }
 public async Task <IEnumerable <HeartDisease> > GetHeartDiseaseRecords()
 {
     try
     {
         return(await DbContext.HeartDiseases.ToListAsync());
     }
     catch (System.Exception ex)
     {
         LogginService.LogException(ex);
     }
     return(null);
 }
コード例 #5
0
        public async Task <HealthUser> AddOrUpdateUser(HealthUser user, string roleName)
        {
            try
            {
                //Get the role
                var role = await DbContext.HealthRoles.SingleOrDefaultAsync(item => item.Name == roleName);

                //Check if the role is vaild and if the user is new
                if (user.Id == Guid.Empty)
                {
                    //Assign the role
                    user.Role = role;
                    //Hash the password
                    user.Password = user.Password.GetMD5Hash();
                    //change the email to lower case
                    user.Email = user.Email.ToLower();
                    //Attach the enitity to the context
                    DbContext.Attach(user);
                    //Mark it as added
                    DbContext.Entry(user).State = EntityState.Added;
                }
                else
                {
                    //Get the user from db
                    var userDb = await DbContext.HealthUsers.SingleOrDefaultAsync(item => item.Id == user.Id);

                    //Update the values
                    userDb.Password       = string.IsNullOrEmpty(user.Password) ? userDb.Password : user.Password.GetMD5Hash();
                    userDb.PhoneNumber    = user.PhoneNumber;
                    userDb.Gender         = user.Gender;
                    userDb.DOB            = user.DOB;
                    userDb.MedicalHistory = user.MedicalHistory;
                    userDb.Note           = user.Note;
                    //Check if the role was changed
                    if (role != null)
                    {
                        userDb.Role = role;
                    }
                    //Markt the entity as modified
                    DbContext.Entry(userDb).State = EntityState.Modified;
                }

                await DbContext.SaveChangesAsync();

                return(user);
            }
            catch (System.Exception ex)
            {
                LogginService.LogException(ex);
            }
            return(null);
        }
コード例 #6
0
        public async Task <HealthRequest> GetHealthRequest(Guid requestId)
        {
            try
            {
                return(await DbContext.HealthRequests.Include(item => item.Replies).SingleOrDefaultAsync(item => item.Id == requestId));
            }
            catch (Exception ex)
            {
                LogginService.LogException(ex);
            }

            return(null);
        }
コード例 #7
0
        public async Task <HealthUser> GetUser(Guid id)
        {
            try
            {
                return(await DbContext.HealthUsers
                       .SingleOrDefaultAsync(item => item.Id == id));
            }
            catch (Exception ex)
            {
                LogginService.LogException(ex);
            }

            return(null);
        }
コード例 #8
0
 public async Task <Course> GetCourse(string name)
 {
     try
     {
         return(await DbContext.Courses
                .Include(item => item.Links)
                .Include(item => item.Sessions).ThenInclude(item => item.Links)
                .Include(item => item.Homeworks).ThenInclude(item => item.Links)
                .SingleOrDefaultAsync(item => item.ShortName.ToLower() == name.ToLower()));
     }
     catch (System.Exception ex)
     {
         LogginService.LogException(ex);
     }
     return(null);
 }
コード例 #9
0
        public async Task <IEnumerable <HealthRequest> > GetHealthRequests(int start, int count, Guid userId, bool isAdmin = false)
        {
            try
            {
                return(await DbContext.HealthRequests.Include(item => item.Replies).Where(item => isAdmin ? true : item.HealthUserId == userId)
                       .OrderBy(item => item.ReplyCount).ThenByDescending(item => item.CreationDate)
                       .Skip(start)
                       .Take(count)
                       .ToListAsync());
            }
            catch (Exception ex)
            {
                LogginService.LogException(ex);
            }

            return(null);
        }
コード例 #10
0
        public bool InitailizeDatabase()
        {
            try
            {
                if (DbContext.Database.EnsureCreated())
                {
                    #region Seed data here

                    #endregion

                    return(true);
                }
            }
            catch (Exception ex)
            {
                LogginService.LogException(ex);
            }
            return(false);
        }
コード例 #11
0
        public async Task <Blog> AddOrUpdateBlog(Blog blog)
        {
            try
            {
                //If there is no id assigned to the blog
                if (blog.Id == Guid.Empty)
                {
                    //Then we need to add a new record
                    DbContext.Blogs.Add(blog);
                }
                else
                {
                    //Get the blokg from the db
                    var blogDb = await DbContext.Blogs.SingleOrDefaultAsync(item => item.Id == blog.Id);

                    //Update the wanted values
                    blogDb.Title   = blog.Title;
                    blogDb.Content = blog.Content;
                    //Only update the image if new value provided
                    if (!string.IsNullOrEmpty(blog.ThumbnailMimeType))
                    {
                        blogDb.ThumbnailBase64   = blog.ThumbnailBase64;
                        blogDb.ThumbnailMimeType = blog.ThumbnailMimeType;
                    }
                    blogDb.Note           = blog.Note;
                    blogDb.LastEditUserId = blog.LastEditUserId;
                    blogDb.PreviewContent = blog.PreviewContent;

                    blog = blogDb;
                    //Mark it as modified
                    DbContext.Entry(blogDb).State = EntityState.Modified;
                }

                await DbContext.SaveChangesAsync();

                return(blog);
            }
            catch (System.Exception ex)
            {
                LogginService.LogException(ex);
            }
            return(null);
        }
コード例 #12
0
        public async Task <Blog> GetBlog(Guid id, bool addVisit = true)
        {
            try
            {
                var blog = await DbContext.Blogs.SingleOrDefaultAsync(item => item.Id == id);

                if (addVisit)
                {
                    blog.VisitCout++;
                    await DbContext.SaveChangesAsync();
                }

                return(blog);
            }
            catch (System.Exception ex)
            {
                LogginService.LogException(ex);
            }
            return(null);
        }
コード例 #13
0
        public async Task <HealthRequestReply> AddOrUpdateRequestReply(HealthRequestReply healthRequestReply)
        {
            try
            {
                //If there is no id assigned to the reply
                if (healthRequestReply.Id == Guid.Empty)
                {
                    //Then we need to add a new record
                    DbContext.HealthRequestReplies.Add(healthRequestReply);

                    //Get the request
                    var healthRequest = await DbContext.HealthRequests.SingleOrDefaultAsync(item => item.Id == healthRequestReply.RequestId);

                    healthRequest.ReplyCount++;

                    DbContext.Entry(healthRequest).State = EntityState.Modified;
                }
                else
                {
                    //Get the blokg from the db
                    var reply = await DbContext.HealthRequestReplies.SingleOrDefaultAsync(item => item.Id == healthRequestReply.Id);

                    //Update the wanted values
                    reply.Content = healthRequestReply.Content;
                    reply.Note    = healthRequestReply.Note;

                    healthRequestReply = reply;
                    //Mark it as modified
                    DbContext.Entry(reply).State = EntityState.Modified;
                }

                await DbContext.SaveChangesAsync();

                return(healthRequestReply);
            }
            catch (System.Exception ex)
            {
                LogginService.LogException(ex);
            }
            return(null);
        }
コード例 #14
0
        public async Task <IEnumerable <object> > GetDbSet(string setName)
        {
            try
            {
                switch (setName.ToLower())
                {
                case "tennis":
                    return(await DbContext.Tennis.ToListAsync());

                case "heartdisease":
                    return(await DbContext.HeartDiseases.ToListAsync());

                default:
                    break;
                }
            }
            catch (System.Exception ex)
            {
                LogginService.LogException(ex);
            }
            return(null);
        }
コード例 #15
0
        public async Task <bool> DeleteBlog(Guid id)
        {
            try
            {
                //Get the blog
                var blogDb = await DbContext.Blogs.SingleOrDefaultAsync(item => item.Id == id);

                if (blogDb != null)
                {
                    //Mark it as deleted
                    DbContext.Entry(blogDb).State = EntityState.Deleted;
                    //Delete the record
                    await DbContext.SaveChangesAsync();
                }
                return(true);
            }
            catch (System.Exception ex)
            {
                LogginService.LogException(ex);
            }
            return(false);
        }
コード例 #16
0
 public async Task <IEnumerable <Blog> > GetBlogs(int start, int count, bool loadImages)
 {
     try
     {
         return(await DbContext.Blogs.Select(blog => new Blog
         {
             Id = blog.Id,
             AutherId = blog.AutherId,
             PreviewContent = blog.PreviewContent,
             Title = blog.Title,
             CreationDate = blog.CreationDate,
             LastUpdatedDate = blog.LastUpdatedDate,
             ThumbnailBase64 = loadImages ? blog.ThumbnailBase64 : string.IsNullOrEmpty(blog.ThumbnailBase64) ? string.Empty : "Data",
             ThumbnailMimeType = loadImages ? blog.ThumbnailMimeType : "",
             VisitCout = blog.VisitCout
         }).OrderByDescending(item => item.VisitCout).Skip(start).Take(count).ToListAsync());
     }
     catch (System.Exception ex)
     {
         LogginService.LogException(ex);
     }
     return(null);
 }