コード例 #1
0
        public async Task <ActionResult <Resource> > PostResource([FromBody] ResourceAddModel ram)
        {
            string   rid      = _globalService.GenRandomId(20);
            Resource resource = new Resource
            {
                ResourceId = rid,
                Name       = ram.Name,
                Url        = ram.Url,
                Type       = ram.Type,
                Size       = ram.Size
            };

            _context.Resource.Add(resource);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (ResourceExists(rid))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetResource", new { id = resource.ResourceId }, resource));
        }
コード例 #2
0
        public async Task <IResultModel> Add(ResourceAddModel model)
        {
            try
            {
                _dbContext.Db.BeginTran();

                var entity = _mapper.Map <ResourceEntity>(model);
                var result = await _resourceRepository.InsertAsync(entity, _dbContext.Db);

                var details = model.Details.Where(m => !string.IsNullOrEmpty(m.FieldName)).ToList();
                if (result && details.Any())
                {
                    details.ForEach(m => { m.ResourceId = entity.Id; });
                    await _resourceDetailRepository.InsertRangeAsync(_mapper.Map <List <ResourceDetailEntity> >(details), _dbContext.Db);
                }

                _dbContext.Db.CommitTran();
            }
            catch (Exception ex)
            {
                _dbContext.Db.RollbackTran();
                return(ResultModel.Failed(ex.Message));
            }

            return(ResultModel.Success());
        }
コード例 #3
0
        public IActionResult AddResource()
        {
            var model = new ResourceAddModel
            {
                Author = User.GetDisplayName()
            };

            return(View(model));
        }
コード例 #4
0
        public IActionResult AddResource(ResourceAddModel model)
        {
            if (ModelState.IsValid)
            {
                using (var uow = _localizationDataService.StartUnitOfWork())
                {
                    var resource = new ResourceEntity
                    {
                        ResourceKey      = model.Name,
                        Author           = model.Author,
                        FromCode         = false,
                        IsHidden         = false,
                        IsModified       = false,
                        ModificationDate = DateTime.Now
                    };
                    uow.ResourceRepository.Add(resource);
                    uow.Commit();
                    return(RedirectToAction(nameof(EditResource), new { resourceId = resource.Id }));
                }
            }

            return(View());
        }
コード例 #5
0
 public Task <IResultModel> Add(ResourceAddModel model)
 {
     return(_service.Add(model));
 }