예제 #1
0
        public IActionResult Create([FromBody] CustomerDto customerDto)
        {
            Notification notification = new Notification();
            bool         uowStatus    = false;

            try
            {
                uowStatus = _unitOfWork.BeginTransaction();

                Customer customer = _customerAssembler.FromCustomerDtoToCustomer(customerDto);
                notification = customer.ValidateForSave();

                if (notification.HasErrors())
                {
                    logger.Message(notification.ErrorMessage(), LogLevel.FunctionalError);
                    return(BadRequest(responseHandler.getAppCustomErrorResponse(notification.ErrorMessage())));
                }

                Specification <Customer> specification = GetUniqueCustomer(customer.Document_Number);
                var uniqueCustomer = _customerRepository.GetUniqueCustomer(specification);

                if (uniqueCustomer != null)
                {
                    notification.AddError("Customer already registered");
                    return(BadRequest(responseHandler.getAppCustomErrorResponse(notification.ErrorMessage())));
                }

                customer.Status = 1;
                _customerRepository.Create(customer);
                _unitOfWork.Commit(uowStatus);

                var message = "Customer " + customer.Id + " created!";
                KipubitRabbitMQ.SendMessage(message);
                logger.Message(message, LogLevel.FunctionalMessage);

                return(Ok(responseHandler.getOkCommandResponse(message, StatusCodes.Status201Created)));
            }
            catch (ArgumentException ex)
            {
                logger.Message(ex.Message, LogLevel.Error);
                return(BadRequest(responseHandler.getAppCustomErrorResponse(ex.Message)));
            }
            catch (Exception ex)
            {
                _unitOfWork.Rollback(uowStatus);
                Console.WriteLine(ex.StackTrace);
                logger.Message(ex.StackTrace, LogLevel.Debug);
                return(StatusCode(StatusCodes.Status500InternalServerError, responseHandler.getAppExceptionResponse()));
            }
        }
예제 #2
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)));
            }
        }
예제 #3
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)));
            }
        }
예제 #4
0
        public IActionResult Create([FromBody] ProductDto ProductDto)
        {
            Notification notification = new Notification();
            bool         uowStatus    = false;

            try
            {
                uowStatus = _unitOfWork.BeginTransaction();

                Product product = _ProductAssembler.FromProductDtoToProduct(ProductDto);
                notification = product.ValidateForSave();

                if (notification.HasErrors())
                {
                    return(BadRequest(responseHandler.getAppCustomErrorResponse(notification.ErrorMessage())));
                }

                product.Status = 1;
                _ProductRepository.Create(product);
                _unitOfWork.Commit(uowStatus);

                var message            = "Product " + product.Id + " created!";
                var messageForRabbitMQ = message + "---" + ProductDto.FirebaseClientKey;
                KipubitRabbitMQ.SendMessage(messageForRabbitMQ);
                return(Ok(responseHandler.getOkCommandResponse(message, StatusCodes.Status201Created)));
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(responseHandler.getAppCustomErrorResponse(ex.Message)));
            }
            catch (Exception ex)
            {
                _unitOfWork.Rollback(uowStatus);
                Console.WriteLine(ex.StackTrace);
                return(StatusCode(StatusCodes.Status500InternalServerError, responseHandler.getAppExceptionResponse()));
            }
        }
예제 #5
0
        public IActionResult CreateDepotOrder([FromBody] DepotOrderDto depotOrderDto)
        {
            bool uowStatus = false;

            try
            {
                var notification = _depotOrderDtoValidator.Validate(depotOrderDto);
                throwErrors(notification);

                uowStatus = _unitOfWork.BeginTransaction();
                var customer = _customerAssembler.FromDepotOrderDtoToCustomer(depotOrderDto);
                // Handled by ConsoleLogger since the console has a loglevel of all
                logger.Message("Verifying customer exists", LogLevel.Debug);
                Customer searchCustomer = _customerRepository.GetByIdentificationNumber(depotOrderDto.CustomerIdentificationNumber);
                logger.Message("Customer retrieved.", LogLevel.Info);

                if (searchCustomer == null)
                {
                    // Handled by ConsoleLogger and FileLogger since filelogger implements Warning & Error
                    logger.Message("Customer doesn't exist", LogLevel.Warning);
                    logger.Message("Preventing NULL exception", LogLevel.Error);
                    // Handled by ConsoleLogger and EmailLogger as it implements functional error
                    logger.Message("Business exception", LogLevel.FunctionalError);
                    return(StatusCode(StatusCodes.Status400BadRequest, _apiResponseHandler.AppErrorResponse("Customer doesn't exist")));
                }

                DepotOrder depotOrder = _depotOrderAssembler.FromDepotOrderDtoToDepotOrder(depotOrderDto);
                Port       _port      = (Port)Enum.Parse(typeof(Port), depotOrderDto.PortISOCode);
                depotOrder.PortId = (long)_port;

                depotOrder.Customer = searchCustomer;
                OceanCarrier _oceanCarrier = (OceanCarrier)Enum.Parse(typeof(OceanCarrier), depotOrderDto.OceanCarrierSCACCode);
                depotOrder.OceanCarrierId = (long)_oceanCarrier;
                depotOrder.ValidateDepotOrder(notification);
                throwErrors(notification);
                _depotOrderRepository.Create(depotOrder);

                List <DepotOrderEquipment> depotOrderEquipments = _depotOrderEquipmentAssembler.ToEntityList(depotOrderDto.Equipments);
                depotOrderEquipments.ForEach(x => x.DepotOrder = depotOrder);
                depotOrderEquipments.ForEach(x => _depotOrderEquipmentRepository.Create(x));
                _unitOfWork.Commit(uowStatus);

                var message = "DepotOrder created!";
                // Handled by ConsoleLogger and EmailLogger
                logger.Message(message, LogLevel.FunctionalMessage);
                KipubitRabbitMQ.SendMessage(message);
                return(StatusCode(StatusCodes.Status201Created, new ApiStringResponseDto(message)));
            }
            catch (ArgumentException ex)
            {
                _unitOfWork.Rollback(uowStatus);
                Console.WriteLine(ex.StackTrace);
                logger.Message(ex.StackTrace, LogLevel.Error);
                KipubitRabbitMQ.SendMessage(ex.StackTrace);
                return(BadRequest(_apiResponseHandler.AppErrorResponse(ex.Message)));
            }
            catch (Exception ex)
            {
                _unitOfWork.Rollback(uowStatus);
                Console.WriteLine(ex.StackTrace);
                logger.Message(ex.StackTrace, LogLevel.Error);
                var message = "Internal Server Error";
                KipubitRabbitMQ.SendMessage(message);
                return(StatusCode(StatusCodes.Status500InternalServerError, _apiResponseHandler.AppErrorResponse(message)));
            }
        }