public async Task <IActionResult> UpdateStatusProject([FromBody] StatusProjectModel status) { string str = ""; foreach (var item in status.statusData) { var thisStatusProject = await _context.StatusProject.SingleOrDefaultAsync(m => m.Id == item.Id); if (item.StatusName == null && item.Serial > 0) { thisStatusProject.Serial = item.Serial; } else if (item.StatusName != null && item.Serial == 0) { thisStatusProject.StatusName = item.StatusName; } else { thisStatusProject.Relation = item.Relation; } _context.StatusProject.Update(thisStatusProject); } await _context.SaveChangesAsync(); str = "update successfully"; var result = JsonConvert.SerializeObject(new { result = str }); return(Ok(result)); }
public async Task <IActionResult> AddNewStatus([FromBody] StatusProjectModel status) { string str = "Create Successfully"; StatusProject statusProject = new StatusProject(); foreach (var item in status.statusData) { statusProject.StatusName = item.StatusName; statusProject.Serial = item.Serial; statusProject.ProjectId = item.ProjectId; statusProject.Relation = 0; } _context.StatusProject.Add(statusProject); await _context.SaveChangesAsync(); var result = JsonConvert.SerializeObject(new { result = str }); return(Ok(result)); }