public ActionResult <SupplierDto> Create([FromBody] NewSupplierDto data)
        {
            try
            {
                var supplier    = _mapper.Map <NewSupplierDto, Supplier>(data);
                var newSupplier = _service.CreateSupplier(supplier);

                var result = _mapper.Map <Supplier, SupplierDto>(newSupplier);
                return(CreatedAtAction(nameof(Get), new { id = newSupplier.Id }, result));
            }
            catch (ArgumentException)
            {
                return(BadRequest());
            }
        }
Beispiel #2
0
        public Guid AddNewSupplier(NewSupplierDto data)
        {
            var s = new Supplier
            {
                Address   = data.Address,
                Created   = DateTime.Now,
                CreatedBy = Guid.Parse("00000000-0000-0000-0000-000000000001"),
                Id        = Guid.NewGuid(),
                IsActive  = true,
                IsDeleted = false,
                Mail      = data.Mail,
                Name      = data.Name,
                Phone     = data.Phone,
                TaxNumber = data.TaxNumber,
                Updated   = DateTime.Now,
                UpdatedBy = Guid.Parse("00000000-0000-0000-0000-000000000001"),
                Vote      = 0,
                VoteCount = 0
            };

            context.Suppliers.Add(s);
            var savedItemCount = context.SaveChanges();

            if (savedItemCount > 0)
            {
                var dto = new SupplierDto
                {
                    Id        = s.Id,
                    Address   = s.Address,
                    Mail      = s.Mail,
                    Name      = s.Name,
                    Phone     = s.Phone,
                    TaxNumber = s.TaxNumber,
                    Vote      = s.Vote,
                    VoteCount = s.VoteCount
                };
                cacheManager.Update <List <SupplierDto> >(nameof(Supplier), (cachedData) =>
                {
                    cachedData.Add(dto);
                });
                return(s.Id);
            }

            return(Guid.Empty);
        }
Beispiel #3
0
 public Guid AddSupplier(NewSupplierDto data)
 {
     return(service.AddNewSupplier(data));
 }