示例#1
0
        public async Task <SampleModel> CreateAsync(CreateSampleModel model,
                                                    CancellationToken cancellationToken = default)
        {
            var sampleEntity = model.MapTo <SampleEntity>();

            _sampleRepo.Add(sampleEntity);

            await GoblinUnitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(true);

            var fileModel = sampleEntity.MapTo <SampleModel>();

            return(fileModel);
        }
示例#2
0
        public bool Create([FromBody] CreateSampleModel model)
        {
            using (var context = new FTDNAContext())
            {
                var status = context.Statuses.FirstOrDefault(s => s.StatusName == model.Status);
                var user   = context.Users.FirstOrDefault(u => u.FirstName == model.FirstName && u.LastName == model.LastName);

                if (status == null)
                {
                    status = new Status()
                    {
                        StatusName = model.Status
                    };
                    context.Statuses.Add(status);
                }

                if (user == null)
                {
                    user = new User()
                    {
                        FirstName = model.FirstName, LastName = model.LastName
                    };
                    context.Users.Add(user);
                }

                context.SaveChanges();

                context.Add(new Sample()
                {
                    BarCode   = model.Barcode,
                    CreatedAt = DateTime.Now,
                    StatusId  = status.StatusId,
                    CreatedBy = user.UserId
                });

                return(true);
            }
        }
示例#3
0
 public async Task <IActionResult> Add(CreateSampleModel model)
 {
     return(Ok(3));
 }
示例#4
0
        public async Task <IActionResult> Upload([FromBody] CreateSampleModel model, CancellationToken cancellationToken = default)
        {
            var sampleModel = await _sampleService.CreateAsync(model, cancellationToken);

            return(Created(Url.Action("Get", new { sampleModel.Id }), sampleModel));
        }