public async Task <Response> Insert(Subject subject) { Response response = Validate(subject); if (response.Success) { subject.SubjectName = subject.SubjectName.ToUpper(); try { using (BiometricPresenceDB dataBase = new BiometricPresenceDB()) { Subject sub = await dataBase.Subjects.FirstOrDefaultAsync(m => m.SubjectName == subject.SubjectName); if (sub != null) { return(ResponseMessage.CreateDuplicateErrorResponse()); } dataBase.Subjects.Add(subject); await dataBase.SaveChangesAsync(); return(ResponseMessage.CreateSuccessResponse()); } } catch (Exception ex) { return(ResponseMessage.CreateErrorResponse(ex)); } } return(response); }
public async Task <Response> Insert(Class clasS) { Response response = Validate(clasS); if (response.Success) { clasS.ClassName = clasS.ClassName.ToUpper(); try { using (BiometricPresenceDB dataBase = new BiometricPresenceDB()) { Class @class = await dataBase.Classes.FirstOrDefaultAsync(m => m.ClassName == clasS.ClassName); if (@class != null) { return(ResponseMessage.CreateDuplicateErrorResponse()); } dataBase.Classes.Add(clasS); await dataBase.SaveChangesAsync(); ResponseMessage.CreateSuccessResponse(); } } catch (Exception ex) { return(ResponseMessage.CreateErrorResponse(ex)); } } return(response); }