//public bool Delete(int id) //{ // var result = new Result<SavedFile>(); // try // { // string query = "delete from SavedFile where SavedFileId=" + id; // return DataAccess.ExecuteQuery(query) > 0; // } // catch (Exception ex) // { // return false; // } //} private bool IsValid(SavedFile obj, Result <SavedFile> result) { if (!ValidationHelper.IsStringValid(obj.FileLink)) { result.HasError = true; result.Message = "Invalid School Name"; return(false); } return(true); }
private SavedFile ConvertToEntity(DataRow row) { try { SavedFile u = new SavedFile(); u.SavedFileId = Int32.Parse(row["CommunicationId"].ToString()); u.UserId = Int32.Parse(row["UserID"].ToString()); u.ProjectSectionId = Int32.Parse(row["ProjectSectionId"].ToString()); u.FileLink = row["comment"].ToString(); return(u); } catch (Exception) { return(null); } }
public Result <SavedFile> Save(SavedFile SavedFile) { var result = new Result <SavedFile>(); try { string query = "select * from SavedFile where SavedFileId=" + SavedFile.SavedFileId; var dt = DataAccess.GetDataTable(query); if (dt == null || dt.Rows.Count == 0) { SavedFile.SavedFileId = GetID(); query = "insert into SavedFile values(" + SavedFile.SavedFileId + "," + SavedFile.ProjectSection + "," + SavedFile.UserId + ",'" + SavedFile.FileLink + "')"; } //else //{ // query = "update SavedFile set ProjectName='" + SavedFile.ProjectName + "',StartTime='" + SavedFile.StartTime + "',EndTime='" + SavedFile.EndTime + "',Description='" + SavedFile.Description + "',ProjectSection='" + SavedFile.ProjectSection + "',Price=" + SavedFile.Price + ",Members=" + SavedFile.Members + " where PostID=" + SavedFile.PostId; //} if (!IsValid(SavedFile, result)) { return(result); } result.HasError = DataAccess.ExecuteQuery(query) <= 0; if (result.HasError) { result.Message = "Something Went Wrong"; } else { result.Data = SavedFile; } } catch (Exception ex) { result.HasError = true; result.Message = ex.Message; } return(result); }
public List <SavedFile> GetAll() { var result = new List <SavedFile>(); try { string query = "select * from SavedFile"; var dt = DataAccess.GetDataTable(query); if (dt != null && dt.Rows.Count != 0) { for (int i = 0; i <= dt.Rows.Count; i++) { SavedFile u = ConvertToEntity(dt.Rows[i]); result.Add(u); } } } catch (Exception ex) { return(result); } return(result); }