Exemplo n.º 1
0
        public async Task <IActionResult> CreateNewBooking([FromBody] BookingRequestModel bookingRequestModel)
        {
            var          loggedIn   = User.Claims.FirstOrDefault(c => c.Type == "sub").Value;
            Guid         LoggedInID = new Guid(loggedIn);
            List <Order> orders     = new List <Order>();

            foreach (var order in bookingRequestModel.Orders)
            {
                orders.Add(new Order
                {
                    BookingId      = order.bookingId,
                    CustomerNumber = order.customerNumber,
                    WareNumber     = order.wareNumber,
                    OrderNumber    = order.orderNumber,
                    InOut          = order.InOut,
                    TotalPallets   = order.TotalPallets,
                    ExternalId     = order.ExternalId,
                    Comment        = order.Comment,
                    BottomPallets  = order.BottomPallets,
                    SupplierName   = order.SupplierName
                });
            }

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

            return(!result.IsSuccessful ? Conflict(result) : new ObjectResult(result));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AssignToShift(Guid id, Guid shiftId)
        {
            var result = await CommandRouter.RouteAsync <AssignUserToShiftCommand, IdResponse>(
                new AssignUserToShiftCommand(id, shiftId));

            return(new ObjectResult(result));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> AssignSupplementTo(Guid userID, Guid suppId)
        {
            var result = await CommandRouter.RouteAsync <AssignSupplementToUserCommand, IdResponse>(
                new AssignSupplementToUserCommand(userID, suppId));

            return(new ObjectResult(result));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> UpdateShiftById([FromBody] UpdateShiftRequestModel shiftRequestModel)
        {
            var result = await CommandRouter.RouteAsync <UpdateShiftCommand, IdResponse>(
                new UpdateShiftCommand(shiftRequestModel.ShiftId, shiftRequestModel.ShiftStart, shiftRequestModel.ShiftEnd, shiftRequestModel.EmployeeId));

            return(new ObjectResult(result));
        }
        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));
        }
        public async Task <IActionResult> DeleteTransporter(Guid id)
        {
            var result =
                await CommandRouter.RouteAsync <DeleteTransporterCommand, IdResponse>(new DeleteTransporterCommand(id));

            return(!result.IsSuccessful ? Conflict(result) : new ObjectResult(result));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> DeleteShiftById(Guid id)
        {
            var result =
                await CommandRouter.RouteAsync <DeleteShiftByIdCommand, IdResponse>(new DeleteShiftByIdCommand(id));

            return(new ObjectResult(result));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> AddUserToShift([FromBody] AddUserToShiftRequestModel addUserToShiftRequestModel)
        {
            var result = await CommandRouter.RouteAsync <AssignUserToShiftCommand, IdResponse>(
                new AssignUserToShiftCommand(addUserToShiftRequestModel.EmployeeOnShift,
                                             addUserToShiftRequestModel.id));

            return(new ObjectResult(result));
        }
        public async Task <IActionResult> CreateNewSupplier([FromBody] SupplierRequestModel supplierRequestModel)
        {
            var result = await CommandRouter.RouteAsync <CreateSupplierCommand, IdResponse>(
                new CreateSupplierCommand(supplierRequestModel.Email,
                                          supplierRequestModel.Telephone, supplierRequestModel.Name));

            return(!result.IsSuccessful ? Conflict(result) : new ObjectResult(result));
        }
Exemplo n.º 10
0
        public async Task <IActionResult> CreateNewOrder([FromBody] OrderRequestModel orderRequestModel)
        {
            var result = await CommandRouter.RouteAsync <CreateOrderCommand, IdResponse>(
                new CreateOrderCommand(orderRequestModel.bookingId, orderRequestModel.customerNumber,
                                       orderRequestModel.orderNumber, orderRequestModel.wareNumber, orderRequestModel.InOut));

            return(!result.IsSuccessful ? Conflict(result) : new ObjectResult(result));
        }
Exemplo n.º 11
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));
        }
        public async Task <IActionResult> CreateNewTransporter([FromBody] TransporterRequestModel transporterRequestModel)
        {
            var result = await CommandRouter.RouteAsync <CreateTransporterCommand, IdResponse>(
                new CreateTransporterCommand(transporterRequestModel.Email,
                                             transporterRequestModel.Telephone, transporterRequestModel.Address,
                                             transporterRequestModel.Name));

            return(!result.IsSuccessful ? Conflict(result) : new ObjectResult(result));
        }
Exemplo n.º 13
0
        public async Task <IActionResult> AddManyShifts([FromBody] AddManyShifts addUserToShiftRequestModel)
        {
            var result = await CommandRouter.RouteAsync <AddManyShiftsCommand, IdResponse>(
                new AddManyShiftsCommand(addUserToShiftRequestModel.listOfShifts));



            return(new ObjectResult(result));
        }
Exemplo n.º 14
0
        public async Task <IActionResult> UpdateShiftAndEmployee(
            [FromBody] UpdateShiftAndEmployeeRequestModel updateShiftAndEmployeeRequestModel)
        {
            var result = await CommandRouter.RouteAsync <CreateShiftWithEmployeeCommand, IdResponse>(
                new CreateShiftWithEmployeeCommand(updateShiftAndEmployeeRequestModel.ShiftStart,
                                                   updateShiftAndEmployeeRequestModel.ShiftEnd, updateShiftAndEmployeeRequestModel.EmployeeId));

            return(new ObjectResult(result));
        }
        public async Task <IActionResult> CreateNewSchedule([FromBody] ScheduleRequesteModel scheduleRequesteModel)
        {
            var result = await CommandRouter.RouteAsync <CreateScheduleCommand, IdResponse>(
                new CreateScheduleCommand(scheduleRequesteModel.ScheduleDay, scheduleRequesteModel.CreatedBy,
                                          scheduleRequesteModel.MischellaneousPallets, scheduleRequesteModel.shifts, scheduleRequesteModel.Intervals, scheduleRequesteModel.ScheduleId
                                          , scheduleRequesteModel.Name));

            return(!result.IsSuccessful ? Conflict(result) : new ObjectResult(result));
        }
        public async Task <IActionResult> CreateUser([FromBody] CreateUserRequestModel requestModel)
        {
            /*
             * //baseurl for creating user on identityServer
             * var baseurl = _identityConfig.Value.IdentityServerUrl + "/identity/users";
             *
             * var httpClient = new HttpClient();
             *
             * httpClient.DefaultRequestHeaders
             *  .Accept
             *  .Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
             *
             *
             * //Serialize object to json-format
             * var json = JsonConvert.SerializeObject(new CreateIdentityUser
             * {
             *  AuthLevel = requestModel.AccessLevel,
             *  Email = requestModel.Email,
             *  Password = requestModel.Password,
             *
             *
             * }, Formatting.Indented);
             *
             * var httpContent = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
             *
             * //Create user on identityServer
             * var identityResult = await httpClient.PostAsync(baseurl, httpContent);
             *
             * //Evaluate if the result was succesful or not
             * if (!identityResult.IsSuccessStatusCode)
             * {
             *  if (identityResult.Content != null)
             *  {
             *      var errorMsg = await identityResult.Content.ReadAsStringAsync();
             *      return StatusCode((int)identityResult.StatusCode , errorMsg);
             *  }
             *  return StatusCode((int)identityResult.StatusCode, identityResult.ReasonPhrase);
             * }
             */
            //Since the result was succesfull, try and read the result for an id generated from the identityServer
            var id = Guid.NewGuid();

            var response = await CommandRouter.RouteAsync <CreateUserCommand, IdResponse>(
                new CreateUserCommand(id, requestModel.Name, requestModel.Email, requestModel.Password, requestModel.AccessLevel, requestModel.BaseWage, requestModel.EmploymentDate));

            if (!response.IsSuccessful)
            {
                return(StatusCode(400, response.Message));
            }

            return(new ObjectResult(response.Id));
        }
Exemplo n.º 17
0
        public async Task <IActionResult> CreateShift([FromBody] CreateShiftRequestModel requestModel)
        {
            Console.WriteLine();
            var response = await CommandRouter.RouteAsync <CreateShiftCommand, IdResponse>(
                new CreateShiftCommand(requestModel.ShiftStart, requestModel.ShiftEnd, requestModel.EmployeeId));

            if (!response.IsSuccessful)
            {
                return(StatusCode(401, response.Message));
            }

            return(new ObjectResult(response.Id));
        }
Exemplo n.º 18
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));
        }
Exemplo n.º 19
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));
        }
        public async Task <IActionResult> CreateSupplement([FromBody] CreateSupplementRequestModel requestModel)
        {
            var list = new List <HourInfo>();

            foreach (var hourInfoRequestModel in requestModel.TimeRange)
            {
                list.Add(new HourInfo(hourInfoRequestModel.FromHour, hourInfoRequestModel.ToHour));
            }

            var response = await CommandRouter.RouteAsync <CreateSupplementCommand, IdResponse>(
                new CreateSupplementCommand(requestModel.Name, requestModel.Decription, requestModel.IsStaticSupplement, requestModel.SupplementValue, requestModel.SupplementDays, list));

            if (!response.IsSuccessful)
            {
                return(StatusCode(401, response.Message));
            }

            return(new ObjectResult(response.Id));
        }
Exemplo n.º 21
0
        public async Task <IActionResult> DeleteUserById(Guid id)
        {
            var baseurl        = _identityConfig.Value.IdentityServerUrl + "/identity/users/" + id;
            var httpClient     = new HttpClient();
            var identityResult = await httpClient.DeleteAsync(baseurl);

            if (!identityResult.IsSuccessStatusCode)
            {
                if (identityResult != null)
                {
                    var errorMsg = await identityResult.Content.ReadAsStringAsync();

                    return(StatusCode((int)identityResult.StatusCode, errorMsg));
                }
                return(StatusCode((int)identityResult.StatusCode, identityResult.ReasonPhrase));
            }

            var result = await CommandRouter.RouteAsync <DeleteUserByIdCommand, IdResponse>(new DeleteUserByIdCommand(id));

            return(new ObjectResult(result));
        }
        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));
        }
        public async Task <IActionResult> InsertManySchedules(
            [FromBody] ManySchedulesRequestModels scheduleRequesteModels)
        {
            List <Schedule> list = new List <Schedule>();

            foreach (var VARIABLE in scheduleRequesteModels.Schedules)
            {
                list.Add(new Schedule
                {
                    CreatedBy             = VARIABLE.CreatedBy,
                    Intervals             = VARIABLE.Intervals,
                    MischellaneousPallets = VARIABLE.MischellaneousPallets,
                    Name        = VARIABLE.Name,
                    ScheduleDay = VARIABLE.ScheduleDay,
                    ScheduleId  = VARIABLE.ScheduleId
                });
            }

            var result =
                await CommandRouter.RouteAsync <InserManySchedulesCommand, IdResponse>(
                    new InserManySchedulesCommand(list));

            return(new ObjectResult(result));
        }