示例#1
0
        public async Task <IActionResult> PostWorksheet([FromBody] WorksheetDTO worksheetDTO)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                // check if there's any material added
                if (worksheetDTO.Materials.Count <= 0)
                {
                    return(BadRequest("The worksheet has to have at least one material!"));
                }

                Worksheet worksheet = _unitOfWork.Worksheets.Add(worksheetDTO);
                await _unitOfWork.Complete();

                return(CreatedAtAction("GetWorksheet", new { id = worksheet.Id }, worksheet.Id));
            } catch (Exception ex)
            {
                _logger.LogError("Unexpected error has occured during HTTP request: ", ex.Message);
                return(StatusCode(500, $"Unexpected error while creating worksheet: {ex.Message}"));
            }
        }
示例#2
0
 private void CloseWorksheet()
 {
     if (MessageBox.Show("A lezárt munkalapot nem fogja tudni tovább szerkeszteni. Biztosan folytatni szeretné?", "Megerősítés",
                         MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
     {
         WorksheetDTO existingWorksheet = _model.Worksheets.FirstOrDefault(w => w.Appointment.Id == WorksheetUnderEdit.Appointment.Id);
         if (existingWorksheet != null)
         {
             _model.Worksheets.Remove(existingWorksheet);
         }
         _model.Worksheets.Add(new WorksheetDTO
         {
             Appointment = WorksheetUnderEdit.Appointment,
             Items       = WorksheetUnderEdit.Items.ToList(),
             FinalPrice  = WorksheetUnderEdit.FinalPrice,
             Closed      = true
         });
         AppointmentDTO appointmentToUpdate = _model.AppointmentList.First(a => a.Id == WorksheetUnderEdit.Appointment.Id);
         appointmentToUpdate.HasWorksheet       = true;
         appointmentToUpdate.HasClosedWorksheet = true;
         Appointments = new ObservableCollection <AppointmentDTO>(_model.AppointmentList);
         OnEditingFinished();
     }
     else
     {
         // do nothing
     }
 }
示例#3
0
 public CreateWorksheetViewModel(IWorksheetService worksheetService, INavigation navigation)
 {
     _worksheetService           = worksheetService;
     _navigation                 = navigation;
     _worksheet                  = new WorksheetDTO();
     this.CreateWorksheetCommand = new DelegateCommand(async() => await this.CreateWorksheetAsync());
 }
示例#4
0
 /// <summary>
 /// Creates a new worksheet
 /// </summary>
 /// <param name="worksheetDTO">The new worksheet</param>
 /// <param name="argToken">The user's token</param>
 /// <returns>The created worksheet's ID</returns>
 public async Task <int> CreateWorksheetAsync(WorksheetDTO worksheetDTO, string argToken)
 {
     try
     {
         return(await _carService.CreateAsync <WorksheetDTO, int>(_url, worksheetDTO, argToken));
     } catch (Exception ex)
     {
         throw ex;
     }
 }
示例#5
0
        public async Task <bool> SaveWorksheetAsync(WorksheetDTO worksheet)
        {
            try
            {
                HttpResponseMessage response = await _client.PostAsJsonAsync("api/worksheets/", worksheet);

                return(response.IsSuccessStatusCode);
            }
            catch (Exception ex)
            {
                throw new PersistenceUnavailableException(ex);
            }
        }
示例#6
0
 public void OnNavigatedTo(NavigationContext navigationContext)
 {
     try
     {
         // getting the worksheet data
         _worksheet = (WorksheetDTO)navigationContext.Parameters["Worksheet"];
     } catch (Exception ex)
     {
         _navigation.EventAggregator.GetEvent <UnexpectedErrorEvent>()
         .Publish($"An unexpected error has occurred: {ex.Message}");
         _navigation.NavigateTo("Reservations", new NavigationParameters());
     }
 }
示例#7
0
        /// <summary>
        /// Navigates to the Worksheet page
        /// with relevant worksheet data
        /// </summary>
        /// <param name="worksheet">The worksheet to show on Worksheet page</param>
        private void ToWorksheet(WorksheetDTO worksheet)
        {
            NavigationParameters navigationParameters = new NavigationParameters
            {
                {
                    "User", this.User
                },
                {
                    "Worksheet", worksheet
                }
            };

            _navigation.NavigateTo("Worksheet", navigationParameters);
        }
        public void PostWorksheet_Unauthorized()
        {
            // GIVEN
            DateTime    testTime        = DateTime.Now.AddHours(1);
            int         testId          = 1;
            string      testWorkType    = "maintenance";
            Appointment testAppointment = new Appointment
            {
                Id       = 1,
                Mechanic = testMechanic1,
                Partner  = testPartner,
                Time     = testTime,
                WorkType = testWorkType,
                Note     = ""
            };

            _context.Appointments.Add(testAppointment);
            _context.SaveChanges();

            WorksheetDTO testData = new WorksheetDTO
            {
                Id          = testId,
                Appointment = new AppointmentDTO
                {
                    Id       = testId,
                    Time     = testTime,
                    WorkType = testWorkType,
                    Partner  = new UserDTO
                    {
                        Id   = 3,
                        Name = "Partner"
                    }
                },
                Items      = new List <WorkItemDTO>(),
                FinalPrice = 0,
                Closed     = true
            };
            WorksheetsController underTest = new WorksheetsController(_context);

            SetupUser(underTest, "mechanic456");
            // WHEN
            var result = underTest.PostWorksheet(testData);

            // THEN
            Assert.IsNotNull(result);
            var objectResult = result as UnauthorizedResult;

            Assert.IsInstanceOf <UnauthorizedResult>(objectResult, result.GetType().ToString());
        }
示例#9
0
 private void EditWorksheet(AppointmentDTO appointment)
 {
     if (appointment != null && WorksheetUnderEdit == null && !appointment.HasClosedWorksheet)
     {
         WorksheetUnderEdit = new WorksheetViewModel
         {
             Appointment = appointment,
             ItemList    = _model.ItemList,
             FinalPrice  = 0
         };
         if (appointment.HasWorksheet)
         {
             WorksheetDTO worksheet = _model.Worksheets.Find(w => w.Appointment.Id == appointment.Id);
             WorksheetUnderEdit.Items      = new ObservableCollection <WorkItemDTO>(worksheet.Items);
             WorksheetUnderEdit.FinalPrice = worksheet.FinalPrice;
         }
         OnEditingStarted();
     }
 }
        public IActionResult PostWorksheet([FromBody] WorksheetDTO worksheetDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            Appointment appointment = _context.Appointments.Include(a => a.Partner).Include(a => a.Mechanic).FirstOrDefault(a => a.Id == worksheetDTO.Appointment.Id);

            if (appointment == null)
            {
                return(BadRequest("Appointment doesn't exist."));
            }
            if (!User.Identity.Name.Equals(appointment.Mechanic.UserName))
            {
                return(Unauthorized());
            }
            try
            {
                Worksheet worksheetToAdd = new Worksheet
                {
                    AppointmentId = appointment.Id,
                    Appointment   = appointment,
                    FinalPrice    = worksheetDTO.FinalPrice,
                };
                worksheetToAdd.Items = new List <WorksheetWorkItem>();
                foreach (WorkItemDTO item in worksheetDTO.Items)
                {
                    worksheetToAdd.Items.Add(new WorksheetWorkItem
                    {
                        Item  = item.Item,
                        Price = item.Price
                    });
                }
                var addedWorksheet = _context.Worksheets.Add(worksheetToAdd);
                _context.SaveChanges();
                return(CreatedAtAction("GetWorksheet", new { id = addedWorksheet.Entity.Id }, worksheetDTO));
            }
            catch
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
示例#11
0
        private void SaveWorksheet()
        {
            WorksheetDTO existingWorksheet = _model.Worksheets.FirstOrDefault(w => w.Appointment.Id == WorksheetUnderEdit.Appointment.Id);

            if (existingWorksheet != null)
            {
                _model.Worksheets.Remove(existingWorksheet);
            }
            _model.Worksheets.Add(new WorksheetDTO
            {
                Appointment = WorksheetUnderEdit.Appointment,
                Items       = WorksheetUnderEdit.Items.ToList(),
                FinalPrice  = WorksheetUnderEdit.FinalPrice
            });
            AppointmentDTO appointmentToUpdate = _model.AppointmentList.First(a => a.Id == WorksheetUnderEdit.Appointment.Id);

            appointmentToUpdate.HasWorksheet = true;
            Appointments = new ObservableCollection <AppointmentDTO>(_model.AppointmentList);
            OnEditingFinished();
        }
 public void OnNavigatedTo(NavigationContext navigationContext)
 {
     try
     {
         // getting the worksheet data
         _materials.Clear();
         _totalPrice = 0;
         this.User   = (UserDTO)navigationContext.Parameters["User"];
         WorksheetDTO worksheet = (WorksheetDTO)navigationContext.Parameters["Worksheet"];
         this.Reservation         = worksheet.Reservation;
         this.Reservation.Partner = worksheet.Partner;
         this.Materials           = worksheet.Materials.ToList <MaterialDTO>();
         foreach (MaterialDTO material in this.Materials)
         {
             this.TotalPrice += (material.Price * material.Quantity);
         }
     } catch (Exception ex)
     {
         this.ErrorMessage = ex.Message;
     }
 }
示例#13
0
        public IActionResult GetWorksheet([FromRoute] int id)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                WorksheetDTO worksheet = _unitOfWork.Worksheets.GetWorksheet(id);

                if (worksheet == null)
                {
                    return(NotFound("Workheet cannot be found!"));
                }

                return(Ok(worksheet));
            } catch (Exception ex)
            {
                _logger.LogError("Unexpected error has occured during HTTP request: ", ex.Message);
                return(StatusCode(500, $"Unexpected error while getting worksheet: {ex.Message}"));
            }
        }
        public void PostWorksheet_BadRequest()
        {
            // GIVEN
            DateTime testTime     = DateTime.Now.AddHours(1);
            int      testId       = 1;
            string   testWorkType = "maintenance";

            WorksheetDTO testData = new WorksheetDTO
            {
                Id          = testId,
                Appointment = new AppointmentDTO
                {
                    Id       = testId,
                    Time     = testTime,
                    WorkType = testWorkType,
                    Partner  = new UserDTO
                    {
                        Id   = 3,
                        Name = "Partner"
                    }
                },
                Items      = new List <WorkItemDTO>(),
                FinalPrice = 0,
                Closed     = true
            };
            WorksheetsController underTest = new WorksheetsController(_context);

            SetupUser(underTest, "mechanic123");
            // WHEN
            var result = underTest.PostWorksheet(testData);

            // THEN
            Assert.IsNotNull(result);
            var badResult = result as BadRequestObjectResult;

            Assert.IsInstanceOf <BadRequestObjectResult>(badResult, result.GetType().ToString());
        }