示例#1
0
        public async Task <IActionResult> Create([FromBody] AssignedVariantDTO model)
        {
            var assignedVariant = new AssignedVariant {
                UserId = model.UserId, VariantId = model.VariantId, AssignDateTime = DateTime.Now
            };

            try
            {
                await _db.AssignedVariants.AddAsync(assignedVariant);

                await _db.SaveChangesAsync();
            }
            catch (DbUpdateException e)
            {
                await Response.WriteAsync(e.Message);
            }
            return(Ok(model));
        }
示例#2
0
        public async Task <IActionResult> Update([FromBody] AssignedVariantDTO model, [FromHeader] int assignedVariantId)
        {
            var assignedVariantUpdate = await _db.AssignedVariants.FirstOrDefaultAsync(aw => aw.AssignedVariantId == assignedVariantId);

            if (assignedVariantUpdate != null)
            {
                try
                {
                    assignedVariantUpdate.UserId    = model.UserId;
                    assignedVariantUpdate.VariantId = model.VariantId;
                    _db.AssignedVariants.Update(assignedVariantUpdate);
                    await _db.SaveChangesAsync();
                }
                catch (DbUpdateException e)
                {
                    await Response.WriteAsync(e.Message);
                }
                return(Ok(assignedVariantId));
            }
            return(NotFound("Update does not exist assigned variant"));
        }