Пример #1
0
 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));
     }
 }
Пример #2
0
        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;
        }
Пример #3
0
        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;
        }
Пример #4
0
        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;
        }
Пример #5
0
 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));
     }
 }
Пример #6
0
 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));
     }
 }
Пример #7
0
        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;
        }
Пример #8
0
        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;
        }
Пример #9
0
        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;
        }
Пример #10
0
        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;
        }
Пример #11
0
 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));
     }
 }
Пример #12
0
 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;
 }
Пример #13
0
        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;
        }
Пример #14
0
        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;
        }
Пример #15
0
        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;
        }