public JTodoService() { try { _repo = Utils.GetRepository(""); } catch (Exception ex) { _log.Error(ex); ServiceDataFault fault = new ServiceDataFault() { Issue = "DataLayer Injection Fail", Details = ex.ToString() }; throw new FaultException<ServiceDataFault>(fault, new FaultReason(fault.Issue)); } }
bool ITodoService.AddCategory(Entity.Category category) { Category cat = null; try { cat = _repo.AddCategory(category); } catch (Exception ex) { _log.Error(ex); ServiceDataFault fault = new ServiceDataFault() { Issue = "AddCategory Fail", Details = ex.ToString() }; throw new FaultException<ServiceDataFault>(fault, new FaultReason(fault.Issue)); } return cat != null; }
bool ITodoService.ChangePassword(string username, string newPassword) { bool success = false; try { if (_repo.UserExists(username)) { _repo.ChangePassword(username, newPassword); success = true; } } catch (Exception ex) { _log.Error(ex); ServiceDataFault fault = new ServiceDataFault() { Issue = "ChangePassword Fail", Details = ex.ToString() }; throw new FaultException<ServiceDataFault>(fault, new FaultReason(fault.Issue)); } return success; }
Task ITodoService.AddTask(long catId, Task task) { Task newTask = null; try { newTask = _repo.AddTask(catId, task); } catch (Exception ex) { _log.Error(ex); ServiceDataFault fault = new ServiceDataFault() { Issue = "AddTask Fail", Details = ex.ToString() }; throw new FaultException<ServiceDataFault>(fault, new FaultReason(fault.Issue)); } return newTask; }
void ITodoService.UpdateTask(Task task) { try { _repo.UpdateTask(task); } catch (Exception ex) { _log.Error(ex); ServiceDataFault fault = new ServiceDataFault() { Issue = "UpdateTask Fail", Details = ex.ToString() }; throw new FaultException<ServiceDataFault>(fault, new FaultReason(fault.Issue)); } }
bool ITodoService.UpdateCategory(Category category) { try { return _repo.UpdateCategory(category); } catch (Exception ex) { _log.Error(ex); ServiceDataFault fault = new ServiceDataFault() { Issue = "UpdateCategory Fail", Details = ex.ToString() }; throw new FaultException<ServiceDataFault>(fault, new FaultReason(fault.Issue)); } }
bool ITodoService.RemoveCategory(long catId) { bool success = false; try { success = _repo.RemoveCategory(catId); } catch (Exception ex) { _log.Error(ex); ServiceDataFault fault = new ServiceDataFault() { Issue = "RemoveCategory Fail", Details = ex.ToString() }; throw new FaultException<ServiceDataFault>(fault, new FaultReason(fault.Issue)); } return success; }
RegisterResult ITodoService.Register(string username, string password) { RegisterResult result = new RegisterResult() { ResultString = ResultCodes.RegisterUserFail, UserId = 0 }; try { if (!String.IsNullOrEmpty(username) && !String.IsNullOrEmpty(password)) { if (!_repo.UserExists(username)) { User user = _repo.AddUser(username, password); result.ResultString = ResultCodes.RegisterUserSuccess; result.Username = user.Username; result.UserId = user.Id; _log.Info(String.Format("New user is registered: {0}", user.Username)); } else { result.ResultString = ResultCodes.RegisterUserExists; } } } catch (Exception ex) { _log.Error(ex); ServiceDataFault fault = new ServiceDataFault() { Issue = "Register Fail", Details = ex.ToString() }; throw new FaultException<ServiceDataFault>(fault, new FaultReason(fault.Issue)); } return result; }
long ITodoService.GetUserId(string username) { long id = -1; try { id = _repo.GetUserId(username); } catch (Exception ex) { _log.Error(ex); ServiceDataFault fault = new ServiceDataFault() { Issue = "GetUserId Fail", Details = ex.ToString() }; throw new FaultException<ServiceDataFault>(fault, new FaultReason(fault.Issue)); } return id; }
LoginResult ITodoService.Login(string username, string password) { LoginResult result = null; try { int resultInt; User user = _repo.Login(username, password, out resultInt); LoginStatus status = (LoginStatus)resultInt; result = new LoginResult(); switch (status) { case (LoginStatus.Success): result.ResultString = ResultCodes.LoginSuccess; result.UserId = user.Id; result.Username = user.Username; _log.Info(String.Format("Log in Successful for user: {0}", user.Username)); break; case (LoginStatus.WrongPass): result.ResultString = ResultCodes.LoginWrongPassword; break; case (LoginStatus.WrongUser): result.ResultString = ResultCodes.LoginWrongUser; break; } } catch (Exception ex) { _log.Error(ex); ServiceDataFault fault = new ServiceDataFault() { Issue = "Login Fail", Details = ex.ToString() }; throw new FaultException<ServiceDataFault>(fault, new FaultReason(fault.Issue)); } return result; }
Task ITodoService.GetTask(long taskId) { try { return _repo.GetTask(taskId); } catch (Exception ex) { _log.Error(ex); ServiceDataFault fault = new ServiceDataFault() { Issue = "GetTask Fail", Details = ex.ToString() }; throw new FaultException<ServiceDataFault>(fault, new FaultReason(fault.Issue)); } }
CIcon ITodoService.GetIcon(long id) { CIcon icon = null; try { icon = _repo.GetIcon(id); } catch (Exception ex) { _log.Error(ex); ServiceDataFault fault = new ServiceDataFault() { Issue = "GetIcon Fail", Details = ex.ToString() }; throw new FaultException<ServiceDataFault>(fault, new FaultReason(fault.Issue)); } return icon; }
Category ITodoService.GetCategory(long catId) { Category cat = null; try { cat = _repo.GetCategory(catId); } catch (Exception ex) { _log.Error(ex); ServiceDataFault fault = new ServiceDataFault() { Issue = "GetCategory Fail", Details = ex.ToString() }; throw new FaultException<ServiceDataFault>(fault, new FaultReason(fault.Issue)); } return cat; }
List<Task> ITodoService.GetAllTasks(long catId) { List<Task> list = new List<Task>(); try { list = _repo.GetAllTasks(catId); } catch (Exception ex) { _log.Error(ex); ServiceDataFault fault = new ServiceDataFault() { Issue = "GetAllTasks Fail", Details = ex.ToString() }; throw new FaultException<ServiceDataFault>(fault, new FaultReason(fault.Issue)); } return list; }
List<Category> ITodoService.GetAllCategories(string username) { List<Category> list = new List<Category>(); try { list = _repo.GetAllCategories(_repo.GetUserId(username)); } catch (Exception ex) { _log.Error(ex); ServiceDataFault fault = new ServiceDataFault() { Issue = "GetAllCategories Fail", Details = ex.ToString() }; throw new FaultException<ServiceDataFault>(fault, new FaultReason(fault.Issue)); } return list; }