//creating method to add data coming from angular project through url public async Task <Object> AddFullDetail(DateSheetViewModel dateSheet) { if (ModelState.IsValid) { DateSheet model = new DateSheet { ID = dateSheet.ID, Class = authDb.Classes.Where(a => a.ID == dateSheet.Class).FirstOrDefault(), Subject = authDb.Courses.Where(a => a.ID == dateSheet.Subject).FirstOrDefault(), Teacher = authDb.Teachers.Where(a => a.ID == dateSheet.Teacher).FirstOrDefault(), Date = dateSheet.Date, StartDate = dateSheet.StartDate, EndDate = dateSheet.EndDate, DateSheetName = dateSheet.DateSheetHeader, }; if (authDb.DateSheet.Any(a => a.Class == model.Class && a.Date == model.Date)) { await Task.Run(() => authDb.RemoveRange(authDb.DateSheet.Where(a => a.Class == model.Class && a.Date == model.Date).ToList())); await authDb.SaveChangesAsync(); } await Task.Run(() => authDb.AddAsync(model)); await authDb.SaveChangesAsync(); return(Ok("success")); } return(BadRequest(ModelState)); }