public ContentDE AddContent(ContentDto contentDto) { ContentDE content = _mapper.Map <ContentDE>(contentDto); if (!_courseRepository.CourseExists(contentDto.CourseId)) { throw new AppException("CourseId does not exist"); } UserDE user = _userRepository.GetUser(contentDto.CreatedBy); if (user == null || !user.Role.Equals("lecturer", StringComparison.OrdinalIgnoreCase)) { throw new AppException("Staff " + contentDto.CreatedBy + " does not exist"); } if (!String.IsNullOrEmpty(contentDto.FileName) && String.IsNullOrEmpty(contentDto.Url)) { throw new AppException("Url is empty for " + contentDto.FileName); } content.ContentId = new Guid(); content.CreatedOn = DateTime.Now; _context.tbl_content.Add(content); _context.SaveChanges(); return(content); }
public void DeleteContent(Guid contentId) { ContentDE content = _context.tbl_content.Where(x => x.ContentId == contentId).FirstOrDefault(); if (content == null) { throw new AppException("ContentId does not exist"); } _context.tbl_content.Remove(content); _context.SaveChanges(); }
public void UpdateContent(ContentDto contentDto) { ContentDE content = _context.tbl_content.Where(x => x.ContentId == contentDto.ContentId).FirstOrDefault(); if (content == null) { throw new AppException("ContentId does not exist"); } if (!String.IsNullOrEmpty(contentDto.FileName) && String.IsNullOrEmpty(contentDto.Url)) { throw new AppException("Url is empty for " + contentDto.FileName); } if (contentDto.Datetime > DateTime.MinValue) { content.Datetime = contentDto.Datetime; } if (!String.IsNullOrEmpty(contentDto.Title)) { content.Title = contentDto.Title; } if (!String.IsNullOrEmpty(contentDto.Description)) { content.Description = contentDto.Description; } if (!String.IsNullOrEmpty(contentDto.FileName)) { content.FileName = contentDto.FileName; } if (!String.IsNullOrEmpty(contentDto.Url)) { content.url = contentDto.Url; } _context.tbl_content.Update(content); }