public async Task <IActionResult> PutSubCategory(int id, SubCategory subCategory)
        {
            if (id != subCategory.Id)
            {
                return(BadRequest());
            }

            _context.Entry(subCategory).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SubCategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 2
0
        public async Task <IActionResult> PutResource(int id, Resource resource)
        {
            if (id != resource.Id)
            {
                return(BadRequest());
            }

            _context.Entry(resource).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ResourceExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        /// <summary>
        /// Async applying patch.
        /// </summary>
        /// <param name="resourceId">id of resource</param>
        /// <param name="patchDtos">List of PATCHes</param>
        /// <returns>Modified entity</returns>
        public async Task ApplyPatchAsync(int resourceId, List <PatchDto> patchDtos)
        {
            if (patchDtos == null)
            {
                throw new ArgumentNullException();
            }

            using (var resourceContext = new ResourceContext())
            {
                var entity = resourceContext.Resources.FirstOrDefault(x => x.Id == resourceId);

                if (entity == null)
                {
                    return;
                }

                foreach (var patchDto in patchDtos)
                {
                    var prop = entity.GetType().GetProperty(patchDto.PropertyName, BindingFlags.Public | BindingFlags.Instance);
                    if (prop != null && prop.CanWrite)
                    {
                        prop.SetValue(entity, Convert.ChangeType(patchDto.PropertyValue, prop.PropertyType));
                    }
                }
                var dbEntityEntry = resourceContext.Entry(entity);
                dbEntityEntry.State = EntityState.Modified;
                await resourceContext.SaveChangesAsync();
            }
        }
Esempio n. 4
0
 protected void DownloadMaterial(object sender, EventArgs e)
 {
     Response.ContentType = DetailType.Text;
     Response.AppendHeader("Content-Disposition", "attachment; filename=" + DetailFilename.Text);
     Response.TransmitFile(Server.MapPath(DetailSource.Value));
     Response.End();
     using (ResourceContext db = new ResourceContext())
     {
         int      materialId = Convert.ToInt32(DetailId.Value);
         Material material   = db.MaterialsContext.Find(materialId);
         material.DownloadTimes   = material.DownloadTimes + 1;
         db.Entry(material).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
 public void Update(T obj)
 {
     db.Entry(obj).State = EntityState.Modified;
 }