public async Task <ActionResult <PersonDTO> > PostPerson([FromBody] PersonDTO personDTO)
        {
            //  Location location = mapper.Map<Location>(destinationDTO.LocationDTO);
            // Location createdLocation = await genericLocationRepo.Create(location);
            if (personDTO == null)
            {
                return(BadRequest(new { Message = "No price input" }));
            }

            try
            {
                Person person = mapper.Map <Person>(personDTO);
                var    result = await genericPersonRepo.Create(person);

                if (result == null)
                {
                    return(BadRequest(new { Message = $"Person {personDTO.FirstName} {personDTO.LastName} could not be saved" }));
                }
                return(Created("api/reservations/person", personDTO));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("HandleErrorCode", "Error", new
                {
                    statusCode = 400,
                    errorMessage = $"Creating Person {personDTO.FirstName} {personDTO.LastName} failed : {ex}"
                }));
            }
        }
        public async Task <ActionResult <PriceClassDTO> > PostPrice([FromBody] PriceClassDTO priceDTO)
        {
            //  Location location = mapper.Map<Location>(destinationDTO.LocationDTO);
            // Location createdLocation = await genericLocationRepo.Create(location);
            if (priceDTO == null)
            {
                return(BadRequest(new { Message = "No price input" }));
            }

            try
            {
                PriceClass price  = mapper.Map <PriceClass>(priceDTO);
                var        result = await genericPriceRepo.Create(price);

                if (result == null)
                {
                    return(BadRequest(new { Message = $"Price {priceDTO.Value} could not be saved" }));
                }
                return(Created("api/reservations/price", priceDTO));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("HandleErrorCode", "Error", new
                {
                    statusCode = 400,
                    errorMessage = $"Creating price {priceDTO} failed : {ex}"
                }));
            }
        }
示例#3
0
        public void AddBook(BookDTO book)
        {
            var ganre  = repoG.GetAll().FirstOrDefault(x => x.Name == book.Genre);
            var author = repoA.GetAll().FirstOrDefault(x => x.Name == book.Author);

            var addbook = new Book
            {
                Year   = book.Year,
                Title  = book.Title,
                Price  = book.Price,
                Author = author,
                Genre  = ganre
            };

            repo.Create(addbook);
        }
示例#4
0
        public virtual async Task <IActionResult> Post(TEntitySaveResources saveResource)
        {
            try {
                var entity = _mapper.Map <TEntity>(saveResource);

                _repo.Create(entity);
                await _repo.SaveChangesAsync();


                var resoure = _mapper.Map <TEntityResource>(entity);

                return(CreatedAtAction(nameof(GetAll), resoure));
            } catch (Exception ex) {
                _logger.LogError(ex.Message);
                return(BadRequest());
            }
        }
        public async Task <ActionResult <CategoryEditCreateDTO> > PostCategory([FromBody][Bind("CategoryName")] CategoryEditCreateDTO categoryDTO)
        {
            if (categoryDTO == null)
            {
                return(BadRequest(new { Message = "Geen categorie input" }));
            }
            ;

            var category = mapper.Map <Category>(categoryDTO);

            if (category == null)
            {
                return(BadRequest(new { Message = "Onvoldoende data bij de categorie" }));
            }

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

            try
            {
                //_context.Category.Add(category);
                //await _context.SaveChangesAsync();
                await genericRepo.Create(category);

                return(CreatedAtAction("GetCategoryById", new { id = category.Id }, mapper.Map <CategoryEditCreateDTO>(category)));
            }
            catch (Exception exc)
            {
                //Serilog
                Log.Logger.Warning(LogEventIds.InsertData.ToString() + $" - CategorieController: Exceptie bij toevoegen van {category.CategoryName}: {exc.Message}");

                //Customised gebruikers error
                return(RedirectToAction("HandleErrorCode", "Error", new
                {
                    statusCode = 400,
                    errorMessage = $"Het bewaren van categorie '{category.CategoryName}' is mislukt."
                }));
            }
        }
        public async Task <IHttpActionResult> AddBuild(NewPcBuild newPcBuild)
        {
            if (newPcBuild == null)
            {
                return(BadRequest("no model provided"));
            }
            PCBuildsEntity newUpdateItem = new PCBuildsEntity();


            newUpdateItem.Memory      = newPcBuild.Memory;
            newUpdateItem.DiskStorage = newPcBuild.DiskStorage;
            newUpdateItem.Graphics    = newPcBuild.Graphics;
            newUpdateItem.PowerSupply = newPcBuild.PowerSupply;
            newUpdateItem.PcWeight    = newPcBuild.PcWeight;
            newUpdateItem.Processors  = newPcBuild.Processors;

            if (newPcBuild.Id != 0)
            {
                newUpdateItem.Id = newPcBuild.Id;
                newUpdateItem    = await _pcBuildsRepository.Update(newUpdateItem);
            }
            else
            {
                newUpdateItem = await _pcBuildsRepository.Create(newUpdateItem);
            }


            var checkedUsbId = new List <int>();

            for (var i = 0; i < newPcBuild.Usbs.Count(); i++)
            {
                UsbToBuildEntity UsbToBuild = new UsbToBuildEntity();

                var x = newPcBuild.Usbs[i];
                if (x.Id != 0)
                {
                    UsbToBuild = await _usbToBuildRepo.Get(x.Id);

                    UsbToBuild.Usb      = x.Usb;
                    UsbToBuild.PcBuild  = newUpdateItem;
                    UsbToBuild.NumberOf = x.NumberOf;
                    UsbToBuild          = await _usbToBuildRepo.Update(UsbToBuild);
                }
                else
                {
                    UsbToBuild.Usb      = x.Usb;
                    UsbToBuild.PcBuild  = newUpdateItem;
                    UsbToBuild.NumberOf = x.NumberOf;
                    UsbToBuild          = await _usbToBuildRepo.Create(UsbToBuild);
                };
                checkedUsbId.Add(UsbToBuild.Id);
            }

            var UsbData = await _usbToBuildRepo.Get(x => x.PcBuild.Id == newPcBuild.Id);

            for (var i = 0; i < UsbData.Count(); i++)
            {
                if (checkedUsbId.Contains(UsbData[i].Id))
                {
                    continue;
                }
                else
                {
                    await _usbToBuildRepo.Delete(UsbData[i]);
                }
            }
            newUpdateItem.USBs = await _usbToBuildRepo.Get(x => x.PcBuild.Id == newPcBuild.Id);



            return(Ok(newUpdateItem));
        }
示例#7
0
 public void Create(T entity)
 {
     genericRepo.Create(entity);
 }
 public virtual TKey Create(TModel model)
 {
     return(genericRepo.Create(model));
 }