示例#1
0
        public async Task <IActionResult> Post([FromBody] SupplierCreate command)
        {
            try
            {
                var createTask = await _db.Suppliers.AddAsync(new Supplier()
                {
                    Title = command.Name,
                    Phone = command.Phone,
                    Email = command.Email,
                    Debt  = 0
                });

                await _db.SaveChangesAsync();


                await _postgresContext.Suppliers.AddAsync(
                    new Domain.Entities.Supplies.Supplier(command.Name, command.Phone, command.Email));

                await _postgresContext.SaveChangesAsync();

                return(Ok(new { Id = createTask.Entity.Id, Name = createTask.Entity.Title }));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
示例#2
0
        public async Task <Supplier> Create(SupplierCreate supplierIn)
        {
            var supplier = Supplier.FromCreate(supplierIn);
            await _suppliers.InsertOneAsync(supplier);

            return(supplier);
        }
示例#3
0
        public async Task <ApiResult <int> > Create(SupplierCreate bundle)
        {
            var supplier = _mapper.Map <Supplier>(bundle);

            var code = await _context.ManageCodes.FirstOrDefaultAsync(x => x.Name == bundle.Code);

            var stt = 1;

Location:
            var location = code.Location + stt;

            var str = code.Name + location;

            var checkCode = await _context.Suppliers.AnyAsync(x => x.Code == str);

            if (checkCode)
            {
                stt++;
                goto Location;
            }

            code.Location = location;
            _context.ManageCodes.Update(code);
            await _context.SaveChangesAsync();

            supplier.Code = str;
            _context.Suppliers.Add(supplier);
            await _context.SaveChangesAsync(); // số bản ghi nếu return

            return(new ApiSuccessResult <int>(supplier.Id));
        }
示例#4
0
        public async Task <ApiResult <GetByIdListSupplier> > Create(SupplierCreate bundle)
        {
            var json        = JsonConvert.SerializeObject(bundle);
            var httpContent = new StringContent(json, Encoding.UTF8, "application/json");
            var url         = $"/api/supplier";
            var result      = await Create <GetByIdListSupplier>(url, httpContent);

            return(result);
        }
示例#5
0
        public async Task <IActionResult> Create([FromBody] SupplierCreate request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var resultId = await _supplierService.Create(request);

            if (!resultId.IsSuccessed)
            {
                return(BadRequest(resultId));
            }

            var result = await _supplierService.GetById(resultId.ResultObj);

            return(Ok(result));
        }
示例#6
0
        public async Task <ApiResult <GetByIdListSupplier> > Create(SupplierCreate bundle)
        {
            var result = await _supplierApiClient.Create(bundle);

            return(result);
        }
示例#7
0
        public async Task <ActionResult <Supplier> > Create([FromHeader] string authToken, SupplierCreate supplier)
        {
            if (!await _authenticationService.CheckAccess(authToken, "orderMgr"))
            {
                return(Unauthorized());
            }

            Supplier created = await _supplierService.Create(supplier);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "Document created.",
                                         "suppliers",
                                         created.Id,
                                         JsonSerializer.Serialize(created)
                                         ));

            return(Ok(supplier));
        }