public async Task <IHttpActionResult> DeleteDoctorCategory(DoctorCategoryModel doctorCategory) { if (await DoctorCategoryService.DoctorCategoryExistsForUpdateAndDelete(doctorCategory.ID)) { var doctorCategorytoDelete = new DoctorCategoryModel { ID = doctorCategory.ID, Name = doctorCategory.Name }; CommonResponse roleResponse = await DoctorCategoryService.DeleteDoctorCategory(doctorCategorytoDelete); if (roleResponse.IsError) { return(BadRequest("Error In Deleting The Doctor Category!")); } else { return(Ok("Doctor Category Deleting Successfully!")); } } else { return(BadRequest("Doctor Category Does Not Exist!!")); } }
public async Task <IHttpActionResult> AddDoctorCategory(DoctorCategoryModel doctorCategory) { if (await DoctorCategoryService.DoctorCategoryExists(doctorCategory.Name)) { return(BadRequest("Doctor Category Already Exists")); } else { var doctorCategorytocreate = new DoctorCategoryModel { Name = doctorCategory.Name }; CommonResponse response = await DoctorCategoryService.AddNewDoctorCategory(doctorCategorytocreate); if (response.IsError) { return(BadRequest("Error In Adding The New Doctor Category!")); } else { return(Ok("Doctor Category Added Successfully!")); } } }
public async Task <IActionResult> Post([FromBody] DoctorCategoryModel obj) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var dataModel = _mapper.Map <DoctorCategory>(obj); _context.DoctorCategories.Add(dataModel); await _context.SaveChangesAsync(); return(CreatedAtAction("GetById", new { Id = obj.Id }, dataModel)); }
public static async Task <CommonResponse> AddNewDoctorCategory(DoctorCategoryModel doctorCategory) { CommonResponse response = new CommonResponse(); var dateCreated = DateTime.Now; //String SQL = "INSERT INTO Doctor_Category(Name,DateAdded)" + // "VALUES('" + doctorCategory.Name + "','" + dateCreated + "')"; using (SqlConnection dbConn = new SqlConnection(connectionString)) { try { dbConn.Open(); //SqlCommand cmd = new SqlCommand(); //cmd.CommandType = CommandType.Text; //cmd.CommandText = SQL; //cmd.Connection = dbConn; SqlCommand cmd = new SqlCommand("SP_AddNewDoctorCategory", dbConn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@DoctorCategory", doctorCategory.Name); cmd.Parameters.AddWithValue("@DateAdded", dateCreated); await cmd.ExecuteNonQueryAsync(); dbConn.Close(); response.IsError = false; } catch (Exception ex) { response.IsError = true; } finally { dbConn.Close(); } } return(response); }
public static async Task <CommonResponse> DeleteDoctorCategory(DoctorCategoryModel docCategory) { CommonResponse response = new CommonResponse(); //String SQL = "DELETE FROM Doctor_Category WHERE Name = '" + docCategory.Name + "' AND ID = '" + docCategory.ID + "'"; using (SqlConnection dbConn = new SqlConnection(connectionString)) { try { dbConn.Open(); //SqlCommand cmd = new SqlCommand(); //cmd.CommandType = CommandType.Text; //cmd.CommandText = SQL; //cmd.Connection = dbConn; SqlCommand cmd = new SqlCommand("SP_DeleteDoctorCategory", dbConn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@DoctorCategory", docCategory.Name); cmd.Parameters.AddWithValue("@DoctorCategoryID", docCategory.ID); await cmd.ExecuteNonQueryAsync(); dbConn.Close(); response.IsError = false; } catch (Exception ex) { response.IsError = true; } finally { dbConn.Close(); } } return(response); }
public static async Task <List <DoctorCategoryModel> > GetDoctorCategories() { List <DoctorCategoryModel> DoctorCategories = new List <DoctorCategoryModel>(); using (SqlConnection dbConn = new SqlConnection(connectionString)) { //var isExistingUserQuery = "SELECT * from Doctor_Category"; SqlDataReader reader; try { dbConn.Open(); SqlCommand cmd = new SqlCommand("SP_GetDoctorCategories", dbConn); cmd.CommandType = CommandType.StoredProcedure; reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { DoctorCategoryModel DoctorCategory = new DoctorCategoryModel(); DoctorCategory.ID = reader.GetInt32(0); DoctorCategory.Name = reader.GetString(1); DoctorCategory.DateAdded = reader.GetDateTime(2); DoctorCategories.Add(DoctorCategory); } } } catch (Exception ex) { reader = null; } finally { dbConn.Close(); } return(DoctorCategories); } }