// Method to notify the Trainer of any Task completion. public bool Trainer_Notification(int id, bool done) { try { Task data = taskrepo.ReadById(id); Users trainee = usersrepo.ReadById(data.TraineeId); Users trainer = usersrepo.ReadById(data.TrainerId); EmailQueue email = new EmailQueue(); if (done) { email.ToAddress = trainer.Email; email.FromAddress = "*****@*****.**"; email.Subject = trainee.Name + " Task Update"; email.Body = string.Format("Dear " + trainer.Name + ",<BR><BR> The Task that you assigned to " + trainee.Name + " has been completed. Kindly check whether it is done properly or not.<BR><BR>Sincerely,<BR>Clanstech Team."); int r = emailrepo.Insert(email); if (r >= 1) { return(true); } } else { email.ToAddress = trainer.Email; email.FromAddress = "*****@*****.**"; email.Subject = trainee.Name + " Task Update"; email.Body = string.Format("Dear " + trainer.Name + ",<BR><BR> The Task that you assigned to " + trainee.Name + " is not completed on time. Kindly take appropriate action.<BR><BR>Sincerely,<BR>Clanstech Team."); emailrepo.Insert(email); } } catch (Exception ex) { MethodBase method = MethodBase.GetCurrentMethod(); Exceptions exception = new Exceptions { Number = ex.HResult.ToString(), Message = ex.Message, Method = method.Name, Url = System.Web.HttpContext.Current.Request.Url.AbsoluteUri }; int r = exceptionrepo.Exception_Create(exception); if (r == 0) { exceptionrepo.Exception_InsertInLogFile(exception); } if (constr.State != ConnectionState.Open) { constr.Close(); constr.Open(); } } return(false); }
public int Subject_Create(Subject subject) { try { List <Subject> subjects = new List <Subject>(); subjects = Subject_Read(); for (int i = 0; i < subjects.Count; i++) { if (subject.SubjectName == subjects[i].SubjectName && subjects[i].isDeleted != false) { return(-1); } } SqlCommand cmd = new SqlCommand("Subject_Insert", constr); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@SubjectName", subject.SubjectName); cmd.Parameters.Add("@SubjectId", SqlDbType.Int); cmd.Parameters["@SubjectId"].Direction = ParameterDirection.Output; constr.Open(); cmd.ExecuteNonQuery(); subject.SubjectId = Convert.ToInt32(cmd.Parameters["@SubjectId"].Value); constr.Close(); } catch (Exception ex) { Exceptions exception = new Exceptions { ExceptionNumber = ex.HResult.ToString(), ExceptionMessage = ex.Message, ExceptionMethod = "Subject_Create", ExceptionUrl = "" }; int r = exceptionrepo.Exception_Create(exception); if (r == 0) { exceptionrepo.Exception_InsertInLogFile(exception); } if (constr.State != ConnectionState.Open) { constr.Close(); constr.Open(); } } return(subject.SubjectId); }
/// <summary> /// A Hotel method to Insert an object of Hotels type in the Database. /// </summary> /// <param name="hotel">Hotel type object</param> /// <returns>Unique Hotel ID assigned while inserting the object in database</returns> public int Insert(Hotels hotel) { try { SqlCommand cmd = new SqlCommand("Hotels_Insert", constr); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@HotelName", hotel.HotelName); cmd.Parameters.AddWithValue("@Address", hotel.Address); cmd.Parameters.AddWithValue("@City", hotel.City); cmd.Parameters.AddWithValue("@Locality", hotel.Locality); cmd.Parameters.AddWithValue("@Description", hotel.Description); cmd.Parameters.AddWithValue("@HotelTypeId", hotel.HotelTypeId); cmd.Parameters.AddWithValue("@UserId", hotel.UserId); cmd.Parameters.AddWithValue("@Rooms", hotel.Rooms); cmd.Parameters.Add("@HotelId", SqlDbType.Int); cmd.Parameters["@HotelId"].Direction = ParameterDirection.Output; constr.Open(); cmd.ExecuteNonQuery(); hotel.HotelId = Convert.ToInt32(cmd.Parameters["@HotelId"].Value); constr.Close(); } catch (Exception ex) { MethodBase method = MethodBase.GetCurrentMethod(); Exceptions exception = new Exceptions { ExceptionNumber = ex.HResult.ToString(), ExceptionMessage = ex.Message, ExceptionMethod = method.Name, ExceptionUrl = request.Url.AbsoluteUri }; int r = exceptionrepo.Exception_Create(exception); if (r == 0) { exceptionrepo.Exception_InsertInLogFile(exception); } if (constr.State != ConnectionState.Open) { constr.Close(); constr.Open(); } } return(hotel.HotelId); }
public int Branch_Create(Branch branch) { try { List <Branch> branches = Branch_Read(); for (int i = 0; i < branches.Count; i++) { if (branch.BranchName == branches[i].BranchName && branches[i].isDeleted == false) { return(-1); } } SqlCommand cmd = new SqlCommand("Branch_Insert", constr); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@BranchName", branch.BranchName); cmd.Parameters.Add("@BranchId", SqlDbType.Int); cmd.Parameters["@BranchId"].Direction = ParameterDirection.Output; constr.Open(); cmd.ExecuteNonQuery(); branch.BranchId = Convert.ToInt32(cmd.Parameters["@BranchId"].Value); constr.Close(); } catch (Exception ex) { Exceptions exception = new Exceptions { ExceptionNumber = ex.HResult.ToString(), ExceptionMessage = ex.Message, ExceptionMethod = "Branch_Create", ExceptionUrl = "" }; int r = exceptionrepo.Exception_Create(exception); if (r == 0) { exceptionrepo.Exception_InsertInLogFile(exception); } if (constr.State != ConnectionState.Open) { constr.Close(); constr.Open(); } } return(branch.BranchId); }
//HttpRequest request = HttpContext.Current.Request; /// <summary> /// A EmailQueue method to Insert an object of EmailQueue type in the Database. /// </summary> /// <param name="book">Email type object</param> /// <returns>Unique Email ID assigned while inserting the object in database</returns> public int Insert(Attachment attachment) { try { SqlCommand cmd = new SqlCommand("Attachment_Insert", constr); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Title", attachment.Title); cmd.Parameters.AddWithValue("@Path", attachment.Path); cmd.Parameters.AddWithValue("@Type", attachment.Type); cmd.Parameters.AddWithValue("@TaskId", attachment.TaskId); cmd.Parameters.AddWithValue("@UserId", attachment.UserId); cmd.Parameters.Add("@Id", SqlDbType.Int); cmd.Parameters["@Id"].Direction = ParameterDirection.Output; constr.Open(); cmd.ExecuteNonQuery(); attachment.Id = Convert.ToInt32(cmd.Parameters["@Id"].Value); constr.Close(); } catch (Exception ex) { MethodBase method = MethodBase.GetCurrentMethod(); Exceptions exception = new Exceptions { Number = ex.HResult.ToString(), Message = ex.Message, Method = method.Name, Url = HttpContext.Current.Request.Url.AbsoluteUri }; int r = exceptionrepo.Exception_Create(exception); if (r == 0) { exceptionrepo.Exception_InsertInLogFile(exception); } if (constr.State != ConnectionState.Open) { constr.Close(); constr.Open(); } } return(attachment.Id); }
//HttpRequest request = HttpContext.Current.Request; /// <summary> /// A MailLogs method to Insert an object of MailLogs type in the Database. /// </summary> /// <param name="book">Mail type object</param> /// <returns>Unique Mail ID assigned while inserting the object in database</returns> public int Insert(MailLogs email) { try { SqlCommand cmd = new SqlCommand("Mail_Insert", constr); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ToAddress", email.ToAddress); cmd.Parameters.AddWithValue("@FromAddress", email.FromAdress); cmd.Parameters.AddWithValue("@Subject", email.Subject); cmd.Parameters.AddWithValue("@Body", email.Body); cmd.Parameters.AddWithValue("@EmailStatus", email.EmailStatus); cmd.Parameters.Add("@MailId", SqlDbType.Int); cmd.Parameters["@MailId"].Direction = ParameterDirection.Output; constr.Open(); cmd.ExecuteNonQuery(); email.MailId = Convert.ToInt32(cmd.Parameters["@MailId"].Value); constr.Close(); } catch (Exception ex) { MethodBase method = MethodBase.GetCurrentMethod(); Exceptions exception = new Exceptions { ExceptionNumber = ex.HResult.ToString(), ExceptionMessage = ex.Message, ExceptionMethod = method.Name, ExceptionUrl = HttpContext.Current.Request.Url.AbsoluteUri }; int r = exceptionrepo.Exception_Create(exception); if (r == 0) { exceptionrepo.Exception_InsertInLogFile(exception); } if (constr.State != ConnectionState.Open) { constr.Close(); constr.Open(); } } return(email.MailId); }
public int Homework_Create(Homework homework) { try { SqlCommand cmd = new SqlCommand("Homework_Insert", constr); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@HomeworkName", homework.HomeworkName); cmd.Parameters.AddWithValue("@Path", homework.Path); cmd.Parameters.AddWithValue("@Type", homework.Type); cmd.Parameters.AddWithValue("@StudentId", homework.StudentId); cmd.Parameters.AddWithValue("@FacultyId", homework.FacultyId); cmd.Parameters.Add("@HomeworkId", SqlDbType.Int); cmd.Parameters["@HomeworkId"].Direction = ParameterDirection.Output; constr.Open(); cmd.ExecuteNonQuery(); homework.HomeworkId = Convert.ToInt32(cmd.Parameters["@HomeworkId"].Value); constr.Close(); } catch (Exception ex) { Exceptions exception = new Exceptions { ExceptionNumber = ex.HResult.ToString(), ExceptionMessage = ex.Message, ExceptionMethod = "Homework_Insert", ExceptionUrl = "" }; int r = exceptionrepo.Exception_Create(exception); if (r == 0) { exceptionrepo.Exception_InsertInLogFile(exception); } if (constr.State != ConnectionState.Open) { constr.Close(); constr.Open(); } } return(homework.HomeworkId); }
/// <summary> /// A Role method to Insert an object of Role type in the Database. /// </summary> /// <param name="role">Role type object</param> /// <returns>Unique Role ID assigned while inserting the object in database</returns> public int Insert(Role role) { try { SqlCommand cmd = new SqlCommand("Role_Insert", constr); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@role", role.role); cmd.Parameters.Add("@RoleId", SqlDbType.Int); cmd.Parameters["@RoleId"].Direction = ParameterDirection.Output; constr.Open(); cmd.ExecuteNonQuery(); role.RoleId = Convert.ToInt32(cmd.Parameters["@RoleId"].Value); constr.Close(); } catch (Exception ex) { MethodBase method = MethodBase.GetCurrentMethod(); Exceptions exception = new Exceptions { ExceptionNumber = ex.HResult.ToString(), ExceptionMessage = ex.Message, ExceptionMethod = method.Name, ExceptionUrl = request.Url.AbsoluteUri }; int r = exceptionrepo.Exception_Create(exception); if (r == 0) { exceptionrepo.Exception_InsertInLogFile(exception); } if (constr.State != ConnectionState.Open) { constr.Close(); constr.Open(); } } return(role.RoleId); }
// Method to check all the Tasks for their submit date. public static void CheckTask() { SqlConnection constr = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString); TaskRepository taskrepo = new TaskRepository(); ExceptionRepository exceptionrepo = new ExceptionRepository(); HomeController hc = new HomeController(); try { List <Task> tasks = taskrepo.Read(); for (int i = 0; i < tasks.Count; i++) { if (!tasks[i].isDeleted) { int done = DateTime.Compare(tasks[i].SubmitBy, DateTime.Now); if (done < 0) { hc.Trainer_Notification(tasks[i].Id, false); tasks[i].StatusId = 4; tasks[i].isDeleted = true; taskrepo.Update(tasks[i]); } } } } catch (Exception ex) { MethodBase method = MethodBase.GetCurrentMethod(); Exceptions exception = new Exceptions { Number = ex.HResult.ToString(), Message = ex.Message, Method = method.Name, Url = System.Web.HttpContext.Current.Request.Url.AbsoluteUri }; int r = exceptionrepo.Exception_Create(exception); if (r == 0) { exceptionrepo.Exception_InsertInLogFile(exception); } if (constr.State != ConnectionState.Open) { constr.Close(); constr.Open(); } } }
/// <summary> /// A User method to Insert an object of User type in the Database. /// </summary> /// <param name="user">Parameter of User type</param> /// <returns>Unique user ID assigned while inserting the object in database</returns> public int Insert(Users user) { try { Guid guid = Guid.NewGuid(); SqlCommand cmd = new SqlCommand("User_Insert", constr); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserName", user.UserName); cmd.Parameters.AddWithValue("@Email", user.Email); cmd.Parameters.AddWithValue("@Password", user.Password); cmd.Parameters.AddWithValue("@RoleId", user.RoleId); cmd.Parameters.AddWithValue("@Phone", user.Phone); cmd.Parameters.AddWithValue("@UserGuid", guid); cmd.Parameters.Add("@UserId", SqlDbType.Int); cmd.Parameters["@UserId"].Direction = ParameterDirection.Output; constr.Open(); cmd.ExecuteNonQuery(); user.UserId = Convert.ToInt32(cmd.Parameters["@UserId"].Value); constr.Close(); } catch (Exception ex) { MethodBase method = MethodBase.GetCurrentMethod(); Exceptions exception = new Exceptions { ExceptionNumber = ex.HResult.ToString(), ExceptionMessage = ex.Message, ExceptionMethod = method.Name, ExceptionUrl = request.Url.AbsoluteUri }; int r = exceptionrepo.Exception_Create(exception); if (r == 0) { exceptionrepo.Exception_InsertInLogFile(exception); } if (constr.State != ConnectionState.Open) { constr.Close(); constr.Open(); } } return(user.UserId); }
public int Faculty_Create(Faculty faculty) { try { Guid guid = Guid.NewGuid(); SqlCommand cmd = new SqlCommand("Faculty_Insert", constr); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@FacultyName", faculty.FacultyName); cmd.Parameters.AddWithValue("@Email", faculty.Email); cmd.Parameters.AddWithValue("@Password", faculty.Password); cmd.Parameters.AddWithValue("@Mobile", faculty.Mobile); cmd.Parameters.AddWithValue("@FacultyGuid", guid.ToString()); cmd.Parameters.AddWithValue("@SubjectId", faculty.SubjectId); cmd.Parameters.Add("@FacultyId", SqlDbType.Int); cmd.Parameters["@FacultyId"].Direction = ParameterDirection.Output; constr.Open(); cmd.ExecuteNonQuery(); faculty.FacultyId = Convert.ToInt32(cmd.Parameters["@FacultyId"].Value); constr.Close(); } catch (Exception ex) { Exceptions exception = new Exceptions { ExceptionNumber = ex.HResult.ToString(), ExceptionMessage = ex.Message, ExceptionMethod = "Faculty_Create", ExceptionUrl = "" }; int r = exceptionrepo.Exception_Create(exception); if (r == 0) { exceptionrepo.Exception_InsertInLogFile(exception); } if (constr.State != ConnectionState.Open) { constr.Close(); constr.Open(); } } return(faculty.FacultyId); }
// Method to Send a E-mail from the queue of unsend E-mails in the database. public static void SendEmailFromQueue() { SqlConnection constr = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString); EmailQueueRepository emailrepo = new EmailQueueRepository(); MailLogRepository mailrepo = new MailLogRepository(); ExceptionRepository exceptionrepo = new ExceptionRepository(); try { Emails email = new Emails(); List <EmailQueue> emails = emailrepo.Read(); for (int i = 0; i < emails.Count; i++) { if (!emails[i].isDeleted && emails[i].Tries < 6) { emailrepo.Delete(emails[i].Id); while (emails[i].Tries < 6) { if (email.Send_Mail(emails[i].ToAddress, emails[i].FromAddress, emails[i].Subject, emails[i].Body)) { MailLog mail = new MailLog() { ToAddress = emails[i].ToAddress, FromAddress = emails[i].FromAddress, Subject = emails[i].Subject, Body = emails[i].Body, EmailStatus = true }; mailrepo.Insert(mail); break; } emails[i].Tries++; emailrepo.Undelete(emails[i].Id); } emailrepo.Update(emails[i]); } } } catch (Exception ex) { MethodBase method = MethodBase.GetCurrentMethod(); Exceptions exception = new Exceptions { Number = ex.HResult.ToString(), Message = ex.Message, Method = method.Name, Url = System.Web.HttpContext.Current.Request.Url.AbsoluteUri }; int r = exceptionrepo.Exception_Create(exception); if (r == 0) { exceptionrepo.Exception_InsertInLogFile(exception); } if (constr.State != ConnectionState.Open) { constr.Close(); constr.Open(); } } }