コード例 #1
0
        public async Task <IActionResult> UpdateTransporter(Guid id, [FromBody] TransporterRequestModel transporterRequestModel)
        {
            //var loggedIn = User.Claims.FirstOrDefault(c => c.Type == "sub").Value;


            var Transporter = await QueryRouter.QueryAsync <GetTransporterById, Transporter>(new GetTransporterById(id));

            if (Transporter != null)
            {
                if (String.IsNullOrEmpty(transporterRequestModel.Name))
                {
                    transporterRequestModel.Name = Transporter.Name;
                }
                if (String.IsNullOrEmpty(transporterRequestModel.Address))
                {
                    transporterRequestModel.Address = Transporter.Address;
                }
                if (transporterRequestModel.Telephone == 0)
                {
                    transporterRequestModel.Telephone = Transporter.Telephone;
                }
                if (String.IsNullOrEmpty(transporterRequestModel.Email))
                {
                    transporterRequestModel.Email = Transporter.Email;
                }
            }

            var result = await CommandRouter.RouteAsync <UpdateTransporterCommand, IdResponse>(
                new UpdateTransporterCommand(transporterRequestModel.Email, transporterRequestModel.Telephone,
                                             transporterRequestModel.Address, transporterRequestModel.Name, id)
                );

            return(!result.IsSuccessful ? Conflict(result) : new ObjectResult(result));
        }
コード例 #2
0
        public async Task <IActionResult> GetUserShiftDetailed()
        {
            var result = await
                         QueryRouter.QueryAsync <UserShiftDetailedQuery, List <UserShiftDetailed> >(new UserShiftDetailedQuery());

            return(new ObjectResult(result));
        }
コード例 #3
0
        public async Task <IActionResult> GetWorkSchedule()
        {
            var result = await
                         QueryRouter.QueryAsync <AllShiftsAndEmployeesQuery, List <AllShiftsWithEmployees> >(
                new AllShiftsAndEmployeesQuery());

            return(new ObjectResult(result));
        }
コード例 #4
0
        public async Task <IActionResult> GetALLUsers()
        {
            var result = await QueryRouter.QueryAsync <GetUsers, IEnumerable <User> >(new GetUsers());



            return(new ObjectResult(result));
        }
コード例 #5
0
        public async Task <IActionResult> GetUtilBookingId()
        {
            var result = await QueryRouter.QueryAsync <UtilBookingQuery, UtilBooking>(new UtilBookingQuery());

            Console.WriteLine(result);

            return(new ObjectResult(result));
        }
コード例 #6
0
        public async Task <IActionResult> UpdateUserByIdObjectAsParam(Guid id, UpdateUserRequestModel userRequestModel)
        {
            //*****************Calls update controller on Identity API, so the db is synced***************************
            //var identityBaseurl = _identityConfig.Value.IdentityServerUrl + "/identity/users/" + id;
            var identityBaseurl = "https://localhost:5001/identity/users/" + id;
            var httpClient      = new HttpClient();

            httpClient.DefaultRequestHeaders
            .Accept
            .Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
            var jsonUpdateStatement = JsonConvert.SerializeObject(new UpdateIdentityUser
            {
                Email     = userRequestModel.Email,
                Password  = userRequestModel.Password,
                AuthLevel = userRequestModel.AccessLevel,
            }, Formatting.Indented);

            var httpContent    = new StringContent(jsonUpdateStatement, System.Text.Encoding.UTF8, "application/json");
            var identityResult = await httpClient.PutAsync(identityBaseurl, httpContent);


            if (!identityResult.IsSuccessStatusCode)
            {
                return(StatusCode(400, "Identity server could not be reached."));
            }

            //*********************Update API db (seperate from identity db)************************
            //Gets user from database to handle null and empty variables in the request model
            var user = await QueryRouter.QueryAsync <GetUserById, User>(new GetUserById(id));

            //if the variables are empty or null, (or 0 for access level), they wont be updated
            if (user != null)
            {
                if (string.IsNullOrWhiteSpace(userRequestModel.Name) && !string.IsNullOrWhiteSpace(user.Name))
                {
                    userRequestModel.Name = user.Name;
                }
                if (string.IsNullOrWhiteSpace(userRequestModel.Email) && !string.IsNullOrWhiteSpace(user.Email))
                {
                    userRequestModel.Email = user.Email;
                }
                if (userRequestModel.AccessLevel == 0)
                {
                    userRequestModel.AccessLevel = user.AccessLevel;
                }
                if (userRequestModel.Wage == 0)
                {
                    userRequestModel.Wage = user.BaseWage;
                }
            }


            var result = await CommandRouter.RouteAsync <UpdateUserCommand, IdResponse>(
                new UpdateUserCommand(userRequestModel.Name, userRequestModel.Email, userRequestModel.Password,
                                      userRequestModel.AccessLevel, userRequestModel.Wage, userRequestModel.EmploymentDate, id));

            return(new ObjectResult(result));
        }
コード例 #7
0
        public async Task <IActionResult> GetTransporters()
        {
            // var CurrentUser = User.Claims.FirstOrDefault((c => c.Type == "sub")).Value;

            // Console.WriteLine(CurrentUser);

            var result = await QueryRouter.QueryAsync <TransportersQuery, IList <Transporter> >(new TransportersQuery());

            return(new ObjectResult(result));
        }
コード例 #8
0
        public async Task <IActionResult> GetAllSchedules()
        {
            var result = await QueryRouter.QueryAsync <SchedulesQuery, List <Schedule> >(new SchedulesQuery());

            if (result == null)
            {
                return(new ObjectResult(IdResponse.Unsuccessful("")));
            }

            return(new ObjectResult(result));
        }
コード例 #9
0
        public async Task <IActionResult> UpdateBooking([FromBody] BookingRequestModel bookingRequestModel, Guid id)
        {
            var booking = await QueryRouter.QueryAsync <GetBookingById, Booking>(new GetBookingById(id));

            if (booking != null)
            {
                if (bookingRequestModel.totalPallets == 0)
                {
                    bookingRequestModel.totalPallets = booking.TotalPallets;
                }
                if (DateTimeEmpty(bookingRequestModel.bookingTime))
                {
                    bookingRequestModel.bookingTime = booking.BookingTime;
                }
                if (String.IsNullOrEmpty(bookingRequestModel.transporterName))
                {
                    bookingRequestModel.transporterName = booking.TransporterName;
                }
                if (bookingRequestModel.port == 0)
                {
                    bookingRequestModel.port = booking.Port;
                }
                if (DateTimeEmpty(bookingRequestModel.actualArrival))
                {
                    bookingRequestModel.actualArrival = booking.ActualArrival;
                }
                if (DateTimeEmpty(bookingRequestModel.startLoading))
                {
                    bookingRequestModel.startLoading = booking.StartLoading;
                }
                if (DateTimeEmpty(bookingRequestModel.endLoading))
                {
                    bookingRequestModel.endLoading = booking.EndLoading;
                }
                if (String.IsNullOrEmpty(bookingRequestModel.email))
                {
                    bookingRequestModel.email = booking.Email;
                }
                if (bookingRequestModel.ExternalId == 0)
                {
                    bookingRequestModel.ExternalId = booking.ExternalId;
                }
            }

            var result = await CommandRouter.RouteAsync <UpdateBookingCommand, IdResponse>(
                new UpdateBookingCommand(bookingRequestModel.totalPallets, bookingRequestModel.bookingTime,
                                         bookingRequestModel.transporterName, bookingRequestModel.port, bookingRequestModel.actualArrival,
                                         bookingRequestModel.startLoading, bookingRequestModel.endLoading, bookingRequestModel.email, id, bookingRequestModel.ExternalId));

            return(!result.IsSuccessful ? Conflict(result) : new ObjectResult(result));
        }
コード例 #10
0
        public async Task <IActionResult> GetSalaryForUserWithIdAsync(Guid id, long fromDate, long toDate)
        {
            var from = new DateTime(fromDate);
            var to   = new DateTime(toDate);

            var result = await QueryRouter.QueryAsync <GetSalaryForUserWithId, IEnumerable <ShiftPayment> >(new GetSalaryForUserWithId(id, from, to));

            if (result == null)
            {
                return(NotFound());
            }

            return(new ObjectResult(result));
        }
コード例 #11
0
        public async Task <IActionResult> UpdateOrder(Guid id, [FromBody] OrderRequestModel orderRequestModel)
        {
            var order = await QueryRouter.QueryAsync <GetOrderById, Order>(new GetOrderById(id));

            if (order != null)
            {
                if (String.IsNullOrEmpty(orderRequestModel.customerNumber))
                {
                    orderRequestModel.customerNumber = order.CustomerNumber;
                }
                if (String.IsNullOrEmpty(orderRequestModel.orderNumber))
                {
                    orderRequestModel.orderNumber = order.OrderNumber;
                }
                if (String.IsNullOrEmpty(orderRequestModel.InOut))
                {
                    orderRequestModel.InOut = order.InOut;
                }
                if (orderRequestModel.bookingId == Guid.Empty)
                {
                    orderRequestModel.bookingId = order.BookingId;
                }
                if (orderRequestModel.wareNumber == 0)
                {
                    orderRequestModel.wareNumber = order.WareNumber;
                }
                if (String.IsNullOrEmpty(orderRequestModel.ExternalId))
                {
                    orderRequestModel.ExternalId = order.ExternalId;
                }
                if (String.IsNullOrEmpty(orderRequestModel.Comment))
                {
                    orderRequestModel.Comment = order.Comment;
                }
                if (String.IsNullOrEmpty(orderRequestModel.SupplierName))
                {
                    orderRequestModel.SupplierName = order.SupplierName;
                }
            }

            var result = await CommandRouter.RouteAsync <UpdateOrderCommand, IdResponse>(
                new UpdateOrderCommand(orderRequestModel.bookingId, orderRequestModel.customerNumber,
                                       orderRequestModel.orderNumber, orderRequestModel.wareNumber, orderRequestModel.InOut, id, orderRequestModel.SupplierName, orderRequestModel.ExternalId, orderRequestModel.TotalPallets, orderRequestModel.BottomPallets, orderRequestModel.Comment));

            return(!result.IsSuccessful ? Conflict(result) : new ObjectResult(result));
        }
コード例 #12
0
        public async Task <IActionResult> GetBookingById(Guid id)
        {
            var result = await QueryRouter.QueryAsync <GetBookingById, Booking>(new GetBookingById(id));

            var orders = await QueryRouter.QueryAsync <OrdersQuery, IList <Order> >(new OrdersQuery());

            var ordersWithBookingId = new List <Order>();

            foreach (var order in orders)
            {
                if (order.BookingId == result.InternalId)
                {
                    ordersWithBookingId.Add(order);
                }
            }

            result.Orders = ordersWithBookingId;

            return(new ObjectResult(result));
        }
コード例 #13
0
        public async Task <IActionResult> UpdateSupplier(Guid id, [FromBody] SupplierRequestModel supplierRequestModel)
        {
            var supplier = await QueryRouter.QueryAsync <GetSupplierById, Supplier>(new GetSupplierById(id));

            if (String.IsNullOrEmpty(supplierRequestModel.Name))
            {
                supplierRequestModel.Name = supplier.Name;
            }
            if (String.IsNullOrEmpty(supplierRequestModel.Email))
            {
                supplierRequestModel.Email = supplier.Email;
            }
            if (supplierRequestModel.Telephone == 0)
            {
                supplierRequestModel.Telephone = supplier.Telephone;
            }

            var result = await CommandRouter.RouteAsync <UpdateSupplierCommand, IdResponse>(
                new UpdateSupplierCommand(supplierRequestModel.Email, supplierRequestModel.Telephone,
                                          supplierRequestModel.Name, id)
                );

            return(!result.IsSuccessful ? Conflict(result) : new ObjectResult(result));
        }
コード例 #14
0
        public async Task <IActionResult> GetBydId(Guid id)
        {
            var result = await QueryRouter.QueryAsync <GetTransporterById, Transporter>(new GetTransporterById(id));

            return(new ObjectResult(result));
        }
コード例 #15
0
        public async Task <IActionResult> GetOrders()
        {
            var result = await QueryRouter.QueryAsync <OrdersQuery, IList <Order> > (new OrdersQuery());

            return(new ObjectResult(result));
        }
コード例 #16
0
        public async Task <IActionResult> GetBookings()
        {
            var result = await QueryRouter.QueryAsync <BookingsQuery, IList <Booking> >(new BookingsQuery());

            return(new ObjectResult(result));
        }
コード例 #17
0
        public async Task <IActionResult> GetShiftsForUserWithIdAsync(Guid id)
        {
            var result = await QueryRouter.QueryAsync <GetShiftsForUserWithId, IEnumerable <Shift> >(new GetShiftsForUserWithId(id));

            return(new ObjectResult(result));
        }
コード例 #18
0
        public async Task <IActionResult> GetALLShifts()
        {
            var result = await QueryRouter.QueryAsync <GetAllShifts, IEnumerable <Shift> >(new GetAllShifts());

            return(new ObjectResult(result));
        }
コード例 #19
0
        public async Task <IActionResult> GetScheduleById(Guid id)
        {
            var result = await QueryRouter.QueryAsync <ScheduleByIdQuery, Schedule>(new ScheduleByIdQuery(id));

            return(new ObjectResult(result));
        }
コード例 #20
0
        public async Task <IActionResult> GetWageForUserWithIdAsync(Guid id)
        {
            var result = await QueryRouter.QueryAsync <GetWageForUserWithId, ShiftPayment>(new GetWageForUserWithId(id));

            return(new ObjectResult(result));
        }
コード例 #21
0
        public async Task <IActionResult> GetById(Guid id)
        {
            var result = await QueryRouter.QueryAsync <GetShiftById, Shift>(new GetShiftById(id));

            return(new ObjectResult(result));
        }
コード例 #22
0
        public async Task <IActionResult> GetWorkHoursForUserWithIdAsync(Guid id)
        {
            var shifts = await QueryRouter.QueryAsync <GetWorkHoursForUser, ShiftPayment>(new GetWorkHoursForUser(id));

            return(new ObjectResult(shifts));
        }