예제 #1
0
        public virtual async Task <IActionResult> Edit(string id, FileEntity entity)
        {
            if (id != entity.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var existing = await Repo.GetOne(id);

                if (existing == null)
                {
                    return(NotFound());
                }

                var tempFile = JsonConvert.DeserializeObject <FileEntity>(JsonConvert.SerializeObject(existing));
                tempFile.Protected   = entity.Protected;
                tempFile.Description = entity.Description;

                try
                {
                    var epb = EntityUpdateHelper <FileEntity> .GetEpbFor(tempFile, existing);

                    var updated = await Repo.Patch(epb);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!await Repo.Exists(id))
                    {
                        return(NotFound());
                    }

                    throw;
                }

                return(RedirectToAction(nameof(Index)));
            }

            return(View(entity));
        }
        public virtual async Task <IActionResult> Edit(string id, TE entity)
        {
            if (id != entity.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var existing = await Repo.GetOne(id);

                if (existing == null)
                {
                    return(NotFound());
                }

                try
                {
                    var epb = EntityUpdateHelper <TE> .GetEpbFor(entity, existing);

                    var updated = await Repo.Patch(epb);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!await EntityExists(entity.Id))
                    {
                        return(NotFound());
                    }

                    throw;
                }

                return(RedirectToAction(nameof(Index)));
            }

            return(View(entity));
        }