public LogicResponse Delete(int courseId, int id) { LogicResponse response = new LogicResponse(); Module module = _moduleRepository.Get(courseId, id); if (module == null) { response.Success = false; response.Message = "No se encontró el módulo"; return(response); } try { _moduleRepository.Delete(module); response.Success = true; response.Message = "Se borró el módulo"; return(response); } catch (Exception ex) { response.Success = false; response.Message = "No se pudo borrar el módulo"; return(response); } }
public LogicResponse Register(RegisterDto registerDto) { LogicResponse response = new LogicResponse(); User user = new User() { UserName = registerDto.Username, Email = registerDto.Email, Id = Guid.NewGuid().ToString() }; IdentityResult registerResult = _userManager.CreateAsync(user, registerDto.Password).Result; if (registerResult.Succeeded) { response.Success = true; response.Message = user.Id; } else { response.Success = false; response.Message = "No se pudo registrar el usuario"; } return(response); }
public LogicResponse Delete(int id) { LogicResponse response = new LogicResponse(); Course course = _courseRepository.GetById(id); if (course == null) { response.Success = false; response.Message = "No se encontró el curso"; return(response); } try { _courseRepository.Delete(course); response.Success = true; response.Message = course.Id.ToString(); } catch (Exception ex) { response.Success = false; response.Message = "Error en la base de datos"; } return(response); }
public LogicResponse Edit(LessonDto lessonDto) { LogicResponse response = new LogicResponse(); Course course = _courseRepository.GetById(lessonDto.CourseId); Module module = _moduleRepository.Get(lessonDto.CourseId, lessonDto.ModuleId); if (course == null) { response.Success = false; response.Message = "No se encontró el curso"; return(response); } if (module == null) { response.Success = false; response.Message = "No se encontró el módulo"; return(response); } Lesson lesson = _mapper.Map <LessonDto, Lesson>(lessonDto); try { _lessonRepository.Edit(lesson); response.Success = true; response.Message = lesson.Id.ToString(); return(response); } catch (Exception ex) { response.Success = false; response.Message = "Error al almacenar la clase"; return(response); } }
public LogicResponse Delete(int courseId, int moduleId, int id) { LogicResponse response = new LogicResponse(); Lesson lesson = _lessonRepository.Get(courseId, moduleId, id); if (lesson == null) { response.Success = false; response.Message = "No se encontró la clase que desea eliminar"; return(response); } try { _lessonRepository.Delete(lesson); response.Success = true; response.Message = "Se borró la clase"; return(response); } catch (Exception ex) { response.Success = false; response.Message = "Error al eliminar la clase"; return(response); } }
public LogicResponse Create(ModuleDto moduleDto) { Course course = _courseRepository.GetById(moduleDto.CourseId); LogicResponse response = new LogicResponse(); if (course == null) { response.Message = $"No se encontró el curso con id {moduleDto.CourseId}"; response.Success = false; return(response); } Module module = _mapper.Map <ModuleDto, Module>(moduleDto); module.Course = course; try { int id = _moduleRepository.Create(module); response.Message = id.ToString(); response.Success = true; return(response); } catch (Exception ex) { response.Success = false; response.Message = "Error al almacenar el módulo"; return(response); } }
public LogicResponse Edit(CourseDto courseDto) { LogicResponse response = new LogicResponse(); Course course = _mapper.Map <CourseDto, Course>(courseDto); Course courseDb = _courseRepository.GetById(course.Id); if (courseDb == null) { response.Success = false; response.Message = "No se encontró el curso"; return(response); } try { _courseRepository.Edit(course); response.Success = true; response.Message = course.Id.ToString(); } catch (Exception ex) { response.Success = false; response.Message = "Error al almacenar en la base de datos"; } return(response); }
private void OnRequestPackageCopy() { if (PackageLinks.Count == 0) { UIMessager.ShowMessage("Набор пуст!"); return; } LogicResponse response = new LogicResponse(false); foreach (var link in PackageLinks) { var storagePath = Session.ActiveUser.PrivateStoragePath; if (!Directory.Exists(storagePath)) { UIMessager. ShowMessage("Папка личного хранилища не выбрана! Выберите папку в меню ПРОГРАММА -> Моя учётная запись."); return; } dynamic obj; if (link.LinkedType == "Folder") { obj = link.GetObject() as Folder; } else if (link.LinkedType == "Document") { obj = link.GetObject() as Document; } else { return; } if (DocumentManager.ExistsInPrivateStorage(obj, storagePath)) { if (!ReplaceConfirmationDialog(Link.GetLink(obj))) { return; } } response = DocumentManager.CopyToPrivateStorage(obj, storagePath); if (!response.IsDone) { UIMessager.ShowMessage(response.Message); } } if (response.IsDone) { UIMessager.ShowMessage("Копирование успешно завершено"); } }
private void OnMove() { var response = new LogicResponse(false); foreach (var link in Links) { if (link.LinkedType == "Folder") { if (link.LinkedID == TargetFolder.ID) { UIMessager.ShowMessage("Перемещаемая папка совпадает с целевой папкой. Объект будет пропущен!"); } else { response = DocumentManager.Move(link.GetObject() as Folder, TargetFolder); if (!response.IsDone) { UIMessager.ShowMessage(response.Message); return; } } } if (link.LinkedType == "Document") { var obj = link.GetObject() as Document; if (obj.ParentFolderID == TargetFolder.ID) { UIMessager.ShowMessage("Перемещаемый документ уже находится в целевой папке. Объект будет пропущен!"); } else { response = DocumentManager.Move(obj, TargetFolder); if (!response.IsDone) { UIMessager.ShowMessage(response.Message); return; } } } } UIMessager.ShowMessage(response.Message); if (response.IsDone) { OnRequestClose(); } }
public IActionResult GetCountWeekdays(DateTime firstDate, DateTime secondDate) { LogicResponse <DataCountBetweenTwoDates> logicResponse = _countBetweenTwoDatesBC.GetCountWeekdays <DataCountBetweenTwoDates>(firstDate, secondDate); if (logicResponse.Success) { return(Ok(new { Results = logicResponse.Data.Result })); } else { return(StatusCode(500, $"Error: {logicResponse.Errors}")); } }
public async Task <IActionResult> Delete(int courseId, int id) { LogicResponse response = new LogicResponse(); response = _moduleLogic.Delete(courseId, id); if (response.Success) { return(Ok(id)); } else { return(BadRequest(response.Message)); } }
public async Task <IActionResult> Login([FromBody] LoginDto loginDto) { if (ModelState.IsValid) { LogicResponse response = await _accountLogic.Login(loginDto); if (response.Success) { return(Ok(response.Message)); } else { return(BadRequest(response.Message)); } } return(BadRequest(ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage)); }
public LogicResponse Create(CourseDto courseDto) { LogicResponse response = new LogicResponse(); Course course = _mapper.Map <CourseDto, Course>(courseDto); try { int id = _courseRepository.Create(course); response.Message = id.ToString();; response.Success = true; } catch (Exception ex) { response.Success = false; response.Message = $"No se pudo almancenar en la base de datos el curso {course.Name}"; } return(response); }
public async Task <IActionResult> Edit([FromBody] CourseDto courseDto) { if (ModelState.IsValid) { LogicResponse response = new LogicResponse(); response = _courseLogic.Edit(courseDto); if (response.Success) { return(Ok(response.Message)); } else { return(BadRequest(response.Message)); } } return(BadRequest(ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage)); }
public async Task <LogicResponse> Login(LoginDto loginDto) { LogicResponse response = new LogicResponse(); if (_userManager.Users.All(x => x.UserName != loginDto.Username)) { response.Success = false; response.Message = "No se encontró el usuario"; return(response); } if (_userManager.Users.Any(x => x.UserName.ToUpper() == loginDto.Username.ToUpper() && !x.Enabled)) { response.Success = false; response.Message = "Usuario inactivo"; return(response); } User user = await _userManager.FindByNameAsync(loginDto.Username); var result = await _userManager.CheckPasswordAsync(user, loginDto.Password); if (result) { //generar token string token = GenerateJSONWebToken(user); response.Success = true; response.Message = token; return(response); } else { response.Success = false; response.Message = "Credenciales incorrectas"; return(response); } }
//[Route("[controller]")] public async Task <IActionResult> Create([FromBody] ModuleDto moduleDto) { if (ModelState.IsValid) { LogicResponse response = _moduleLogic.Create(moduleDto); if (response.Success) { moduleDto.Id = Convert.ToInt32(response.Message); return(Created($"/Courses/{moduleDto.CourseId}/Modules/{response.Message}", moduleDto)); } else { return(BadRequest(response.Message)); } } else { return(BadRequest(ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage)); } }
public IActionResult GetCountBusinessDays(DateTime firstDate, DateTime secondDate, [FromBody] dynamic publicHolidays) { List <DateTime> dateList = null; if (publicHolidays != null && publicHolidays.Count > 0) { dateList = JsonConvert.DeserializeObject <List <DateTime> >(publicHolidays.ToString()); } LogicResponse <DataCountBetweenTwoDates> logicResponse = _countBetweenTwoDatesBC.GetCountBusinessDays <DataCountBetweenTwoDates>(firstDate, secondDate, dateList); if (logicResponse.Success) { return(Ok(new { Results = logicResponse.Data.Result })); } else { return(StatusCode(500, $"Error: {logicResponse.Errors}")); } }
public LogicResponse Edit(ModuleDto moduleDto) { LogicResponse response = new LogicResponse(); Course course = _courseRepository.GetById(moduleDto.CourseId); if (course == null) { response.Success = false; response.Message = "No se encontró el curso del módulo a modificar"; return(response); } Module module = _moduleRepository.Get(moduleDto.CourseId, moduleDto.Id); if (module == null) { response.Success = false; response.Message = "No se encontró el módulo"; return(response); } module = _mapper.Map <ModuleDto, Module>(moduleDto); try { _moduleRepository.Edit(module); response.Success = true; response.Message = module.Id.ToString(); return(response); } catch (Exception ex) { response.Success = false; response.Message = "Error al almacenar el módulo"; return(response); } }
public async Task <IActionResult> Post([FromBody] LessonDto lessonDto) { if (ModelState.IsValid) { LogicResponse response = new LogicResponse(); response = _lessonLogic.Create(lessonDto); if (response.Success) { lessonDto.Id = Convert.ToInt32(response.Message); return(Created($"/Courses/{lessonDto.CourseId}/Modules/{lessonDto.ModuleId}/Lessons/{lessonDto.Id}", lessonDto)); } else { return(BadRequest(response.Message)); } } else { return(BadRequest(ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage)); } }
private void OnCopy() { var response = new LogicResponse(false); foreach (var link in Links) { if (link.LinkedType == "Folder") { response = DocumentManager.Copy(link.GetObject() as Folder, TargetFolder); if (!response.IsDone) { UIMessager.ShowMessage(response.Message); return; } } if (link.LinkedType == "Document") { response = DocumentManager.Copy(link.GetObject() as Document, TargetFolder); if (!response.IsDone) { UIMessager.ShowMessage(response.Message); return; } } } UIMessager.ShowMessage(response.Message); if (response.IsDone) { OnRequestClose(); } }
public async Task <IActionResult> Register([FromBody] RegisterDto registerDto) { if (ModelState.IsValid) { try { LogicResponse response = _accountLogic.Register(registerDto); if (response.Success) { return(Ok(response.Message)); } else { return(BadRequest(response.Message)); } } catch (Exception ex) { return(BadRequest("Error al registrar la solicitud")); } } return(BadRequest(ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage)); }