Example #1
0
        public async Task <IActionResult> Delete([FromBody] LabelCollections collections)
        {
            var lab = await db.Labels.FindAsync(collections.LabelCollectionsID);

            db.Entry(lab).State = EntityState.Deleted;
            await db.SaveChangesAsync();

            return(Accepted(collections));
        }
Example #2
0
        public async Task <IActionResult> Edit([FromBody] LabelCollections collections)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new { Error = "Invalid data was submitted", Message = ModelState.Values.First(x => x.Errors.Count > 0).Errors.Select(t => t.ErrorMessage).First() }));
            }
            db.Entry(collections).State = EntityState.Modified;
            await db.SaveChangesAsync();

            return(Accepted(collections));
        }
Example #3
0
        public async Task <IActionResult> Create([FromBody] LabelCollections collections)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new { Error = "Invalid data was submitted", Message = ModelState.Values.First(x => x.Errors.Count > 0).Errors.Select(t => t.ErrorMessage).First() }));
            }
            if (await db.LabelCollections.AnyAsync(x => x.LabelName == collections.LabelName))
            {
                return(BadRequest(new { Message = "Label already exists" }));
            }
            db.Add(collections);
            await db.SaveChangesAsync();

            return(Created($"", collections));
        }