コード例 #1
0
        public async Task <IActionResult> Create([FromBody] TicketTypeDto model)
        {
            var currentUser = await _identityService.GetCurrentUser();

            if (currentUser == null)
            {
                return(BadRequest(new { error = "You are not allowed!" }));
            }

            var person = await _identityService.GetPersonByUserId(currentUser.Id);

            if (person == null)
            {
                return(BadRequest(new { error = "Person was not found" }));
            }

            if (!ModelState.IsValid)
            {
                return(NotFound());
            }

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

            var ticketType = new TicketType()
            {
                Name = model.Name,
            };

            await _ticketTypeService.CreateTicketType(ticketType);

            return(Ok());
        }
コード例 #2
0
        public async Task <IActionResult> UpdateAsync([FromBody] TicketTypeDto model)
        {
            if (model == null)
            {
                return(NotFound());
            }

            var currentUser = await _identityService.GetCurrentUser();

            if (currentUser == null)
            {
                return(BadRequest(new { error = "You are not allowed!" }));
            }

            var person = await _identityService.GetPersonByUserId(currentUser.Id);

            if (person == null)
            {
                return(BadRequest(new { error = "Person was not found" }));
            }

            var ticketType = await _ticketTypeService.GetTicketTypeById(model.Id);

            if (ticketType == null)
            {
                return(BadRequest(new { error = "Selected ticketType was not found" }));
            }

            ticketType.Name    = model.Name;
            ticketType.Deleted = model.Deleted;

            await _ticketTypeService.UpdateTicketType(ticketType);

            return(Ok());
        }
コード例 #3
0
        public IActionResult Edit(int id, TicketTypeDto ticketTypeDto)
        {
            logger.Info(nameof(TicketTypeController.Edit));

            if (id != ticketTypeDto.Id)
            {
                logger.Warn(nameof(TicketTypeController.Edit) + " id is not equal to ticketTypeDto.Id");

                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(View(ticketTypeDto));
            }

            try
            {
                ticketTypeService.Update(ticketTypeDto);
            }
            catch (Exception exception)
            {
                logger.Error(exception);

                return(BadRequest());
            }

            return(RedirectToAction(nameof(Index)));
        }
コード例 #4
0
        public ActionResult PostTicketType([FromBody] TicketTypeDto ticketTypeDto)
        {
            var response = _service.Add(ticketTypeDto);

            _service.Save(response);

            return(new OkObjectResult(response["Output"]));
        }
コード例 #5
0
        public void Update(TicketTypeDto ticketTypeDto)
        {
            if (!ticketTypeValidator.Validate(ticketTypeDto).IsValid)
            {
                throw new ArgumentException(ticketTypeValidator.Validate(ticketTypeDto).Errors.First().ErrorMessage);
            }

            var ticketType = mapper.Map <TicketTypeDto, TicketType>(ticketTypeDto);

            unitOfWork.TicketTypes.Update(ticketType);
            unitOfWork.Save();
        }
コード例 #6
0
        public IActionResult Edit(Guid id, TicketDto ticketDto)
        {
            log.Info(nameof(TicketController.Edit) + ":Post");

            TicketTypeDto ticketType = null;

            if (id != ticketDto.Id)
            {
                log.Warn(nameof(TicketController.Edit) + " id is not equal to ticketDto.Id");

                return(NotFound());
            }

            try
            {
                ticketType = ticketTypeService.GetTicketTypeById(ticketDto.TicketTypeId);

                if (ticketType.IsPersonal && ticketDto.UserId == null)
                {
                    ModelState.AddModelError("", "User is not specified for personal ticket type");
                    InitViewDataForSelectList();

                    return(View(ticketDto));
                }

                if (ModelState.IsValid)
                {
                    ticketService.Update(ticketDto);

                    return(RedirectToAction(nameof(Index)));
                }

                InitViewDataForSelectList(ticketDto);

                return(View(ticketDto));
            }
            catch (Exception e)
            {
                log.Error(e);
                return(BadRequest());
            }
        }
コード例 #7
0
        public TicketTypeServiceTests()
        {
            var mockRepository = new Mock <IRepository <TicketType, int> >();
            var mockUnitOfWork = new Mock <IUnitOfWork>();

            fakeTicketTypes = new List <TicketType>
            {
                new TicketType {
                    Id = 5, TypeName = "Test1", Coefficient = 2.3M, DurationHours = 12, IsPersonal = true
                },
                new TicketType {
                    Id = 7, TypeName = "Test2", Coefficient = 2.4M, DurationHours = 13, IsPersonal = false
                },
                new TicketType {
                    Id = int.MaxValue, TypeName = "Test2", Coefficient = 2.4M, DurationHours = 13, IsPersonal = false
                }
            };

            ticketTypeDto = new TicketTypeDto
            {
                Id            = 3,
                TypeName      = "TestDTO",
                Coefficient   = 2.6M,
                DurationHours = 16,
                IsPersonal    = false
            };

            mockRepository.Setup(m => m.GetAll()).Returns(fakeTicketTypes.AsQueryable);
            mockRepository.Setup(m => m.Get(It.IsAny <int>()))
            .Returns <int>(id => fakeTicketTypes.Single(t => t.Id == id));
            mockRepository.Setup(r => r.Create(It.IsAny <TicketType>()))
            .Callback <TicketType>(t => fakeTicketTypes.Add(ticketType = t));
            mockRepository.Setup(r => r.Update(It.IsAny <TicketType>()))
            .Callback <TicketType>(t => ticketType = t);
            mockRepository.Setup(x => x.Delete(It.IsAny <int>()))
            .Callback <int>(id => fakeTicketTypes.Remove(fakeTicketTypes.Single(t => t.Id == id)));

            mockUnitOfWork.Setup(m => m.TicketTypes).Returns(mockRepository.Object);

            ticketTypeService = new TicketTypeService(mockUnitOfWork.Object);
        }
コード例 #8
0
        public IActionResult Create(TicketTypeDto ticketTypeDto)
        {
            logger.Info(nameof(TicketTypeController.Create));

            if (!ModelState.IsValid)
            {
                return(View(ticketTypeDto));
            }

            try
            {
                ticketTypeService.Create(ticketTypeDto);
            }
            catch (Exception exception)
            {
                logger.Error(exception);

                return(BadRequest());
            }

            return(RedirectToAction(nameof(Index)));
        }