Exemple #1
0
        public IActionResult Create([FromBody] SignUpDto signUpDto)
        {
            Notification notification = new Notification();
            bool         uowStatus    = false;

            try
            {
                uowStatus = _unitOfWork.BeginTransaction();

                Student student = _studentAssembler.FromSignUpDtoToStudent(signUpDto);
                notification = student.validateForSave();

                if (notification.hasErrors())
                {
                    return(StatusCode(StatusCodes.Status400BadRequest, notification.ToString()));
                }

                _studentRepository.Create(student);

                Project project = _projectAssembler.FromSignUpDtoToProject(signUpDto);

                /*Special Case Patternn*/
                var projectGet = ExistProject(project);
                if (!string.IsNullOrEmpty(projectGet.ProjectName))
                {
                    project.Student = student;
                    /*Null Object Pattern*/
                    var calc_NumberDaysProject = new calc_NumberDaysProject();
                    project.NumberDaysProject = calc_NumberDaysProject.getNumberDaysProject(project.NumberDaysProject).GetNumberProjectDays();
                    /*-----------------------------*/

                    _projectRepository.Create(project);
                }

                _unitOfWork.Commit(uowStatus);

                var message = "Customer, user and project created!";
                KipubitRabbitMQ.SendMessage(message);

                return(StatusCode(StatusCodes.Status201Created, new ApiStringResponseDto(message)));
            }
            catch (Exception ex)
            {
                _unitOfWork.Rollback(uowStatus);
                Console.WriteLine(ex.StackTrace);
                var message = "Internal Server Error";
                KipubitRabbitMQ.SendMessage(message);
                return(StatusCode(StatusCodes.Status500InternalServerError, new ApiStringResponseDto(message)));
            }
        }
Exemple #2
0
        public IActionResult Create([FromBody] SignUpDto signUpDto)
        {
            Notification notification = new Notification();
            bool         uowStatus    = false;

            try
            {
                uowStatus = _unitOfWork.BeginTransaction();

                Customer customer = _customerAssembler.FromSignUpDtoToCustomer(signUpDto);
                notification = customer.validateForSave();

                if (notification.hasErrors())
                {
                    return(StatusCode(StatusCodes.Status400BadRequest, notification.ToString()));
                }

                _customerRepository.Create(customer);

                User user = _userAssembler.FromSignUpDtoToUser(signUpDto);
                user.RoleId   = (long)Role.Owner;
                user.Customer = customer;
                _userRepository.Create(user);

                Project project = _projectAssembler.FromSignUpDtoToProject(signUpDto);
                project.Customer = customer;

                _projectRepository.Create(project);

                _unitOfWork.Commit(uowStatus);

                var message = "Customer, user and project created!";
                KipubitRabbitMQ.SendMessage(message);
                return(StatusCode(StatusCodes.Status201Created, new ApiStringResponseDto(message)));
            }
            catch (Exception ex)
            {
                _unitOfWork.Rollback(uowStatus);
                Console.WriteLine(ex.StackTrace);
                var message = "Internal Server Error";
                KipubitRabbitMQ.SendMessage(message);
                return(StatusCode(StatusCodes.Status500InternalServerError, new ApiStringResponseDto(message)));
            }
        }