public IActionResult Like(int id) { if (id < 1) { return(BadRequest("Invalid post id")); } var post = _repos.Posts.GetWith(id, "Likes"); if (post == null) { return(NotFound("Post with that id does not exist in records.")); } if (post.Likes == null) { post.Likes = new List <Like>(); } var like = new Like() { Reaction = Reaction.Like, By = this.GetMyProfile() }; like = _repos.Likes.Create(like); _repos.Commit(); post.Likes.Add(like); post = _repos.Posts.Update(post); _repos.Commit(); return(Ok(post)); }
public async Task OnNewContent(Content content) { if (content.Unit == null) { throw new Exception("Send notifications operation failed.", new Exception("Null unit object in uploaded content.")); } string subject = "New Content Uploaded."; string message = $"Your lecturer has uploaded a {content.Type.ToString()} to '{content.Unit.Name}' " + $"learning materials with the title <b>{content.Title}</b>."; // get all students for this unit IList <Student> students = _repos.StudentUnits .ListWith("Student") .Where(x => x.UnitId == content.Unit.Id) .Select(x => x.Student) .ToList(); IList <AppUser> accounts = GetStudentAccounts(students); // create notifications for all students SendNotifications(message, students); // post in discussion board PostContentToBoard(content); _repos.Commit(); // send emails await SendEmails(subject, message, accounts); }
public IActionResult PostOnBoard(int id, string message) { if (id < 1) { return(BadRequest("Invalid discussion board id")); } var board = _repos.DiscussionBoards .GetWith(id, "Posts"); if (board == null) { return(NotFound("Discussion board with that id does not exist in records.")); } if (board.Posts == null) { board.Posts = new List <Post>(); } var post = new Post() { By = this.GetMyProfile(), Message = message }; post = _repos.Posts.Create(post); _repos.Commit(); board.Posts.Add(post); post = _repos.Posts.Update(post); _repos.Commit(); return(Ok(post)); }
public IActionResult Create(int courseId, UnitViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Unit unit = _mapper.Map <Unit>(model); unit.Code = Guid.NewGuid(); // get course var course = _repos.Courses.Get(courseId); if (course == null) { return(NotFound("No record of that course exists.")); } unit.Course = course; unit = _repos.Units.Create(unit); _repos.Commit(); _notify.OnNewUnit(unit); return(Ok("Created!")); }
public async Task <IActionResult> Create(int unitId, ContentViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (Request.Form.Files == null || Request.Form.Files.Count < 1) { return(BadRequest("No file included in form data.")); } var unit = _repos.Units.Get(unitId); if (unit == null) { return(NotFound("No record of units exists with that Id.")); } IFile file = new FormFile(Request.Form.Files[0]); string uploadResult = await _uploader.Upload(file); if (string.IsNullOrWhiteSpace(uploadResult)) { return(this.Error("Uploading file failed. Please try again.")); } var content = _mapper.Map <DAL.Models.Content>(model); content.FileName = file.FileName; content.Type = file.Format; content.Url = uploadResult; content.Unit = unit; // get & attach lecturer (uploader) var user = await _userManager.GetUserAsync(User); var lecturer = _repos.Lecturers.Get(user.AccountId); if (lecturer == null) { return(this.UnAuthorized("Current user account used in uploading content does not have have a valid Lecturer record.")); } content.UploadedBy = lecturer; // save content finally content = _repos.Contents.Create(content); _repos.Commit(); await _notify.OnNewContent(content); return(Created($"api/contents/{content.Id}", content)); }
public IActionResult Allocate(int id, int unitId) { if (id < 1 || unitId < 1) { return(BadRequest("Invalid class or unit Id.")); } var _class = _repos.Classes.Get(id); if (_class == null) { return(NotFound("Class record with that Id does not exist.")); } var unit = _repos.Units.Get(unitId); if (unit == null) { return(NotFound("Unit with that Id does not exist.")); } unit.Class = _class; unit = _repos.Units.Update(unit); _repos.Commit(); return(Ok("Room allocation successful!")); }
public IActionResult UpdateBio(LecturerViewModel model) { var lecturer = _repos.Lecturers .GetWith(this.GetAccountId(), "Skills"); lecturer.Bio = model.Bio; if (lecturer.Skills == null) { lecturer.Skills = new List <Skill>(); } foreach (var item in model.Skills) { if (lecturer.Skills.Contains(x => x.Name == item.Name)) { continue; } else { lecturer.Skills.Add(item); } } lecturer = _repos.Lecturers.Update(lecturer); _repos.Commit(); return(Ok(lecturer)); }
public async Task <IActionResult> Create(int id, Exam model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id < 1) { return(BadRequest("Invalid unit Id.")); } var unit = _repos.Units.Get(id); if (unit == null) { return(NotFound("Unit does not exist in records.")); } model.Unit = unit; model = _repos.Exams.Create(model); _repos.Commit(); await _notify.OnNewExam(model); return(Ok(model.Id)); }
public void Add(TenantDTO tenantDTO) { var tenant = TenantFactory.Create(tenantDTO.Descricao); ValideTenant(tenant); _repositoryFactory.TenantRepository.Add(tenant); _repositoryFactory.Commit(); }
public IActionResult Enroll(int id) { int account = this.GetAccountId(); Course course = _repos.Courses .GetWith(id, "Units"); Student student = _repos.Students .GetWith(account, "Course"); if (student.Course == null) { student.Course = course; student = _repos.Students.Update(student); } else { StudentCourse studentCourse = new StudentCourse() { CourseId = course.Id, StudentId = account, Course = course, Student = student }; studentCourse = _repos.StudentCourses.Create(studentCourse); } foreach (var item in course.Units) { StudentUnit studentUnit = new StudentUnit() { Student = student, StudentId = student.Id, Unit = item, UnitId = item.Id }; _repos.StudentUnits.Create(studentUnit); } _repos.Commit(); return(RedirectToActionPermanent("EnrollmentSuccess", course)); }
public IActionResult BaseStructure() { var _base = _repos.BaseFeeStructures .ListWith("PreparedBy", "PreparedBy.Profile") .FirstOrDefault(); if (_base == null) { _base = new BaseFeeStructure() { AdminId = this.GetAccountId() }; _base = _repos.BaseFeeStructures.Create(_base); _repos.Commit(); } ViewBag.Notifications = this.GetNotifications(); return(View(_base)); }
public CourseworkProgress GetProgress(int contentId, int studentId) { var progress = _repos.CourseworkProgress .Get(x => x.ContentId == contentId && x.StudentId == studentId); if (progress == null) { progress = new CourseworkProgress() { ContentId = contentId, StudentId = studentId }; progress = _repos.CourseworkProgress.Create(progress); _repos.Commit(); } return(progress); }
public IActionResult Create(Class model) { if (!ModelState.IsValid) { string error = ModelState.Populate().First(); return(BadRequest(error)); } model = _repos.Classes.Create(model); _repos.Commit(); return(Ok("Classroom added successfully!")); }
public IActionResult Create(SchoolViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } School school = _mapper.Map <School>(model); school = _repos.Schools.Create(school); _repos.Commit(); return(Created($"/api/schools/{school.Id}", school)); }
public IActionResult MarkAsRead(IList <Notification> notifications) { if (notifications.Count < 1) { return(Ok()); } foreach (var item in notifications) { var ntf = _repos.Notifications.Get(item.Id); ntf.Read = true; ntf = _repos.Notifications.Update(ntf); } //_repos.Notifications.UpdateMany(notifications.ToArray()); _repos.Commit(); var items = _repos.Notifications.List .Where(x => x.AccountId == this.GetAccountId()) .ToList(); return(Ok(items)); }
public async Task <IActionResult> Create(CourseViewModel model) { Course course = _mapper.Map <Course>(model); course.Code = Guid.NewGuid(); // upload backdrop image if (Request.Form.Files.Count > 0) { var uploadedFile = Request.Form.Files[0]; if (uploadedFile.Length > 0) { IFile file = new FormFile(Request.Form.Files[0]); course.BackdropUrl = await _uploader.Upload(file); } else { course.BackdropUrl = "https://devtimmystorage.blob.core.windows.net/images/education_button2.jpg"; } } // get school var school = _repos.Schools.Get(1); if (school == null) { return(NotFound("Adding course to a non-existant school. School with that Id not found.")); } course.School = school; course = _repos.Courses.Create(course); _repos.Commit(); return(RedirectPermanent(Request.Headers["Referer"].ToString())); }
public FeePayment MakePayment(int student, PaymentMethod method, decimal amount) { if (student < 1) { throw new LepadException("Payment failed! Invalid student id."); } var _student = _repos.Students.GetWith(student, "Payments"); if (_student == null) { throw new LepadException("Payment failed! Student record not found."); } var payment = new FeePayment() { Amount = amount, IsGeneral = true, Method = method, StudentId = student }; payment = _repos.FeePayments.Create(payment); _repos.Commit(); if (_student.Payments == null) { _student.Payments = new List <FeePayment>(); } ; _student.Payments.Add(payment); _student = _repos.Students.Update(_student); _repos.Commit(); return(payment); }
public async Task <IActionResult> GetSession(int id) { if (id < 1) { return(BadRequest("Invalid exam id.")); } AppUser user = await _usermanager.GetUserAsync(User); var exam = _repos.Exams.GetWith(id, "Sessions"); if (exam == null) { return(NotFound("Exam record with that id does not exist.")); } var session = exam.Sessions .FirstOrDefault(x => x.StudentId == user.AccountId); if (session == null) { session = new ExamSession() { ExamId = exam.Id, StudentId = user.AccountId }; session = _repos.ExamSessions.Create(session); exam.Sessions.Add(session); exam = _repos.Exams.Update(exam); _repos.Commit(); } var examViewModel = _dataManager.GetExam(id); var examSession = new ExamSessionViewModel() { Id = session.Id, SessionId = session.SessionId, TotalQuestions = examViewModel.Questions.Count, TotalMarks = examViewModel.Questions.Sum(x => x.Marks), Exam = examViewModel }; return(Ok(examSession)); }
public async Task <IActionResult> Save(double latitude, double longitude) { var result = await _gmaps.ReverseGeocode(latitude, longitude); if (result == null) { return(this.Error(HttpStatusCode.InternalServerError, "Reverse geo-coding operation failed.")); } var profile = this.GetMyProfile(); if (profile.Location == null) { profile.Location = new Location(); } var loc = result.results[0]; profile.Location.Latitude = latitude; profile.Location.Longitude = longitude; profile.Location.FullAddress = loc.formatted_address; // retreive street & city string[] tokens = loc.formatted_address.Split(','); if (tokens.Length > 2) { profile.Location.Street = tokens[0]; profile.Location.City = tokens[1]; } else if (tokens.Length <= 2) { profile.Location.City = tokens[0]; } profile = _repos.Profiles.Update(profile); _repos.Commit(); return(Ok(profile.Location)); }
public async Task <IActionResult> Edit(Profile model) { if (!ModelState.IsValid) { return(View(ModelState)); } var profile = _repos.Profiles.Get(model.Id); if (profile != null) { var result = Services.Extensions.TryUpdate(profile, model).First(); if (result.Key > 0) { profile = _repos.Profiles.Update(result.Value); _repos.Commit(); if (profile.FullNames != User.FullNames()) { // update claims AppUser user = await _userManager.GetUserAsync(User); IList <Claim> claims = await _userManager.GetClaimsAsync(user); // get fullnames claim var claim = claims.FirstOrDefault(x => x.Type == "FullNames"); var new_claim = new Claim("FullNames", profile.FullNames); await _userManager.ReplaceClaimAsync(user, claim, new_claim); } return(LocalRedirect($"/account/profile/{Services.Extensions.GenerateSlug(profile.FullNames)}")); } } ViewBag.error = "An error occured."; return(View(model)); }
public void Add(UsuarioDTO usuarioDTO) { var usuario = new Usuario { Celular = usuarioDTO.Celular, Cpf = usuarioDTO.Cpf, Email = usuarioDTO.Email, Guid = usuarioDTO.Guid, IsAtivo = true, Nome = usuarioDTO.Nome, Perfil = ePerfil.AdministradorSistema, Telefone = usuarioDTO.Telefone, TenantId = 1, }; usuario.SetSenhaCriptografada(usuarioDTO.Senha); usuario.SetSenhaConfirmaCriptografada(usuarioDTO.Senha); ValideUsuario(usuario); _repositoryFactory.UsuarioRepository.Add(usuario); _repositoryFactory.Commit(); }
public async Task <IActionResult> Add(int unitId) { ContentViewModel model = new ContentViewModel { Title = Request.Form["Title"], Description = Request.Form["Desc"] }; if (unitId < 1) { return(BadRequest("Invalid unit id.")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // get unit var unit = _repos.Units.Get(unitId); if (unit == null) { return(NotFound("Unit record with that Id does not exist.")); } // get current user account AppUser user = await _userManager.GetUserAsync(User); //int account = this.GetAccountId(); // get lecturer account var lec = _repos.Lecturers.GetWith(user.AccountId, "Profile"); if (lec == null) { return(NotFound("Current logged in user does not have a valid lecturer account.")); } // get content data var content = new Content() { Title = model.Title, Description = model.Description, Unit = unit, UploadedBy = lec }; int contentType = int.Parse(Request.Form["ContentType"]); if (contentType == 1) { if (string.IsNullOrWhiteSpace(Request.Form["Url"])) { return(Redirect(Request.Headers["Referer"])); } else { content.FileName = "Uploaded via Url"; content.Type = (FormatType)int.Parse(Request.Form["UrlFileType"]); content.Url = Request.Form["Url"]; } } else if (contentType == 2) { // try upload attached file if (Request.Form.Files.Count < 1) { return(BadRequest("No file attached to the upload request. Contents must point to valid uploaded files.")); } IFile file = new FormFile(Request.Form.Files[0]); content.FileName = file.FileName; content.Type = file.Format; try { content.Url = await _uploader.Upload(file); } catch (Exception) { return(this.Error(HttpStatusCode.InternalServerError, "Uploading file failed! Please try again.")); } } try { content = _repos.Contents.Create(content); _repos.Commit(); await _notify.OnNewContent(content); return(LocalRedirect($"/contents/{content.Id}/{Services.Extensions.GenerateSlug(content.Title)}")); } catch (Exception ex) { return(this.Error(ex)); } }