示例#1
0
        public static void Query3()
        {
            InitializeMapperQ3();

            using (var db = new CarDealerContext())
            {
                var xmlDoc = new XDocument();

                var cars = new SuppliersDTO()
                {
                    suppliers = db.Suppliers
                                .Where(c => c.IsImporter == false)
                                .ProjectTo <SupplierDTO>()
                                .ToList()
                };

                var serializer = new XmlSerializer(typeof(SuppliersDTO));
                var writer     = new StreamWriter("../../Export/local-suppliers.xml");

                using (writer)
                {
                    serializer.Serialize(writer, cars);
                }
            }
        }
 public bool Create(SuppliersDTO suppliersDTO)
 {
     using (UnitOfWork unitOfWork = new UnitOfWork()){
         var supplier = new Suppliers()
         {
             Name      = supplier.Name,
             CreatedOn = DateTime.Now
         };
         unitOfWork.SuppliersRepository.Create(supplier);
         return(unitOfWork.Save());
     }
 }
 public IActionResult Create([FromBody] SuppliersDTO suppliersDTO)
 {
     if (!suppliersDTO.isValid())
     {
         return(BadRequest());
     }
     if (suppliersService.Create(suppliersDTO))
     {
         return(NoContent());
     }
     return(BadRequest());
 }
 public IActionResult Update([FromRoute] int id, [FromBody] SuppliersDTO suppliersDTO)
 {
     if (!suppliersDTO.isValid())
     {
         return(BadRequest());
     }
     suppliersDTO.Id = id;
     if (suppliersService.Update(suppliersDTO))
     {
         return(NoContent());
     }
     return(BadRequest());
 }
 public bool Update(SuppliersDTO suppliersDTO)
 {
     using (UnitOfWork unitOfWork = new UnitOfWork()){
         var res = unitOfWork.SuppliersRepository.GetById(suppliersDTO.Id);
         if (res == null)
         {
             return(false);
         }
         res.Name      = suppliersDTO.Name;
         res.UpdatedOn = DateTime.Now;
         unitOfWork.SuppliersRepository.Update(res);
         return(unitOfWork.Save());
     }
 }