public async Task <ActionResult <PCBuild> > Get(Guid Id)
        {
            PCBuild build = await this._repository.Get(Id);

            if (build == null)
            {
                return(this.NotFound());
            }

            return(build);
        }
        public async Task <ActionResult <PCBuild> > Post([FromBody] PCBuild model)
        {
            try
            {
                model.CreatedDate  = DateTime.UtcNow;
                model.ModifiedDate = DateTime.UtcNow;

                await this._repository.Add(model);

                return(this.StatusCode(StatusCodes.Status201Created, model));
            }
            catch (Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, ex));
            }
        }
        public async Task <ActionResult <PCBuild> > Delete(Guid Id)
        {
            try
            {
                PCBuild build = await this._repository.Delete(Id);

                if (build == null)
                {
                    return(this.StatusCode(StatusCodes.Status404NotFound));
                }
                return(this.StatusCode(StatusCodes.Status200OK));
            }
            catch (Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, ex));
            }
        }
        public async Task <IActionResult> Put([FromBody] PCBuild model)
        {
            try
            {
                if (model != null)
                {
                    model.ModifiedDate = DateTime.UtcNow;

                    await this._repository.Update(model);

                    return(this.StatusCode(StatusCodes.Status201Created, model));
                }

                return(this.StatusCode(StatusCodes.Status204NoContent));
            }
            catch (Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, ex));
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            ProcessorDTO proc = new ProcessorDTO()
            {
                Model = "I7",
                Price = 100
            };

            RAMDTO ram1 = new RAMDTO()
            {
                Model = "Kinston",
                Price = 100
            };

            RAMDTO ram2 = new RAMDTO()
            {
                Model = "GSkill",
                Price = 120
            };

            PCBuildDTO buildDto = new PCBuildDTO()
            {
                Name = "Test",
                TotalPrice = 1000,
                Processor = proc,
                RAMs = new List<RAMDTO>() { ram1, ram2 }
            };

            Mapper.Initialize(cfg => cfg.CreateMap<PCBuildDTO, PCBuild>().ConstructProjectionUsing(p=>p.RAMs.Select(s => new RAM { Model = s.Model, Price = s.Price,  })

            PCBuild build = Mapper.Map<PCBuildDTO, PCBuild>(buildDto);




            Console.ReadKey();
        }