コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Added,AddedUserId")] Models.Entity entity)
        {
            if (id != entity.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(entity);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EntityExists(entity.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(entity));
        }
コード例 #2
0
        public async Task PatchEntity(Entity entity)
        {
            try
            {
                Models.Entity dbEntity = await GetBase().Where(e => e.Id == entity.Id).SingleAsync();

                if (entity.Name != null)
                {
                    dbEntity.Name = entity.Name;
                }
                if (entity.Permissions != null && entity.Permissions.Id != 0)
                {
                    dbEntity.PermissionsId = (int)entity.Permissions?.Id;
                }
                if (entity.Details != null && entity.Details.Count() > 0)
                {
                    dbEntity.Details = dbEntity.Details.Concat(_mapper.Map(entity.Details)).ToList();
                }
                if (entity.Properties != null && entity.Properties.Count() > 0)
                {
                    dbEntity.Details = dbEntity.Details.Concat(_mapper.Map(entity.Properties)).ToList();
                }
                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                throw new NotFoundException("Entity not found", e);
            }
        }
コード例 #3
0
        public async Task <Entity> AddEntity(Entity entity)
        {
            Models.Entity storing = _mapper.Map(entity);
            _context.Entities.Add(storing);
            await _context.SaveChangesAsync();

            return(_mapper.Map(storing));
        }
コード例 #4
0
        public async Task <IActionResult> Create([Bind("Id,Added,AddedUserId")] Models.Entity entity)
        {
            if (ModelState.IsValid)
            {
                _context.Add(entity);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(entity));
        }
コード例 #5
0
        public async Task UpdateEntity(Entity entity)
        {
            try {
                Models.Entity dbEntity = await GetBase().Where(e => e.Id == entity.Id).SingleAsync();

                Models.Entity mapped = _mapper.Map(entity);
                dbEntity.Name          = mapped.Name;
                dbEntity.PermissionsId = mapped.PermissionsId;
                dbEntity.Details       = mapped.Details;
                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                throw new NotFoundException("Entity not found", e);
            }
        }
コード例 #6
0
 internal static void Set(this List <Models.Entity> list, Models.Entity entity)
 {
     Set(list, entity, e => e.Name);
 }