public DeleteResponse Delete(DeleteRequest req)
        {
            var res = new DeleteResponse();


            var user = _userRepository.FindById(req.Id);

            if (user == null)
            {
                return((DeleteResponse)
                       res.ReturnErrorResponseWith(MagicStrings.Users.Error.NotFound));
            }

            try
            {
                _userRepository.Delete(user);
                _authService.DeleteUser(user.Email);
                _uow.Commit();
            }
            catch (Exception ex)
            {
                return((DeleteResponse)res.ReturnErrorResponseWith(ex.Message));
            }

            _authService.DeleteUser(user.UserName);

            res.Success   = true;
            res.IdDeleted = req.Id;
            return(res);
        }
Example #2
0
        public DeleteResponse Delete(Guid userId, Guid id)
        {
            var res = new DeleteResponse();

            var ticket = _ticketRepository.FindById(id);

            if (ticket == null)
            {
                return((DeleteResponse)res.ReturnErrorResponseWith("Ticket not found"));
            }

            _ticketRepository.Delete(ticket);

            try
            {
                _uow.Commit();
            }
            catch (Exception ex)
            {
                return((DeleteResponse)res.ReturnErrorResponseWith(ex.Message));
            }

            res.IdDeleted = ticket.Id;
            res.Success   = true;

            return(res);
        }
        public DeleteResponse Delete(string userId, Guid id)
        {
            var res = new DeleteResponse();

            var project = _projectRepository.FindById(id);

            if (project == null)
            {
                return((DeleteResponse)res.ReturnErrorResponseWith("Project not found."));
            }

            var owners = project.ProjectUsersReq.Where(pur => pur.Role.RoleName == "PROJECT_MANAGER").ToList();

            if (owners.Find(pur => pur.Sender.Id.Equals(Guid.Parse(userId)) ||
                            pur.UserAssigned.Id.Equals(Guid.Parse(userId))) == null)
            {
                return((DeleteResponse)res.ReturnErrorResponseWith("Only project manager can delete projects!"));
            }

            _projectRepository.Delete(project);

            try
            {
                _uow.Commit();
            }
            catch (Exception ex)
            {
                return((DeleteResponse)res.ReturnErrorResponseWith(ex.Message));
            }

            res.Success   = true;
            res.IdDeleted = project.Id;
            return(res);
        }
        public DeleteResponse Delete(Guid userId, Guid id)
        {
            var res = new DeleteResponse();

            var pur = _projectUserReqRepository.FindById(id);

            if (pur == null)
            {
                return((DeleteResponse)res.ReturnErrorResponseWith("Specified request not found"));
            }

            if (!pur.Sender.Id.Equals(userId))
            {
                return((DeleteResponse)res.ReturnErrorResponseWith("You can delete only requests that you sent!"));
            }

            _projectUserReqRepository.Delete(pur);

            try
            {
                _uow.Commit();
            }
            catch (Exception ex)
            {
                return((DeleteResponse)res.ReturnErrorResponseWith(ex.Message));
            }

            res.Success   = true;
            res.IdDeleted = id;
            return(res);
        }
        public DeleteResponse Delete(DeleteRequest req, string userId)
        {
            var res = new DeleteResponse();


            var user = _userRepository.FindById(req.Id);

            if (user == null)
            {
                return((DeleteResponse)
                       res.ReturnErrorResponseWith(MagicStrings.Users.Error.NotFound));
            }

            if (!user.Id.ToString().ToLower().Equals(userId.ToString().ToLower()))
            {
                return((DeleteResponse)
                       res.ReturnErrorResponseWith(MagicStrings.Users.Error.Unauthorized));
            }

            try
            {
                _userRepository.Delete(user);
                _uow.Commit();
            }
            catch (Exception ex)
            {
                return((DeleteResponse)res.ReturnErrorResponseWith(ex.Message));
            }

            Console.WriteLine("deleting in auth");
            _authService.DeleteUser(user.UserName);

            res.Success   = true;
            res.IdDeleted = req.Id;
            return(res);
        }