示例#1
0
        public async Task <int?> Update(int id, Category data, string identity)
        {
            if (identity == null)
            {
                return(null);
            }

            Models.Category raw = await context.Categories.FindAsync(id);

            if (raw == null || raw.UserId != identity)
            {
                return(null);
            }

            Models.Category value = Models.Category.FromModel(data);
            raw.Name   = value.Name;
            raw.Color  = value.Color;
            raw.Status = value.Status;

            context.Categories.Update(raw);
            await context.SaveChangesAsync();

            return(raw.Id);
        }