// [Route("Home/Login")] public HttpResponseMessage Login(string username, string passcode) { if (username == null || passcode == null) { var message = Request.CreateResponse(HttpStatusCode.NonAuthoritativeInformation, "Please input Credentials"); return(message); } else { string Hash_Password = GetMD5Hash(passcode); Users userinfo = Data_Users.GetUserInfo(username); if (userinfo == null || userinfo.Passcode != Hash_Password) { var message = Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Please input Valid Credentials"); //display home screen return(message); } else { var message = Request.CreateResponse(HttpStatusCode.Created, userinfo); return(message); } } }
public IHttpActionResult SaveDelegation(Delegations d) { int IsAllocated; Users user = Data_Users.GetUserInfo(d.Username); using (SqlConnection conn = new SqlConnection(DataLink.connectionString)) { conn.Open(); string cmdtext = @"insert into Delegation (DeptID,UserID,StartDate,EndDate,Username,DelegationStatus) values ('" + user.DeptID_FK + "','" + user.UserID + "','" + d.StartDate + "','" + d.EndDate + "','" + user.Username + "','Allocated')"; SqlCommand cmd = new SqlCommand(cmdtext, conn); IsAllocated = cmd.ExecuteNonQuery(); } if (IsAllocated != 0) { using (SqlConnection conn = new SqlConnection(DataLink.connectionString)) { conn.Open(); string cmdtext = @"UPDATE Users SET role ='InterimHead' where UserID = '" + user.UserID + "'"; SqlCommand cmd = new SqlCommand(cmdtext, conn); IsAllocated = cmd.ExecuteNonQuery(); } } return(Ok()); }
public ActionResult RemoveDelegation(Delegations Dg) //this method triggers when the "ADD" button is pressed for the item. { int IsUnAllocated; //Debug.WriteLine(s.ItemID); using (SqlConnection conn = new SqlConnection(DataLink.connectionString)) { conn.Open(); string cmdtext = @"UPDATE Delegation SET DelegationStatus ='UnAllocated' where DelegationID = '" + Dg.DelegationID + "'"; SqlCommand cmd = new SqlCommand(cmdtext, conn); IsUnAllocated = cmd.ExecuteNonQuery(); } if (IsUnAllocated != 0) { using (SqlConnection conn = new SqlConnection(DataLink.connectionString)) { conn.Open(); string cmdtext = @"UPDATE Users SET role ='DepStaff' where Username = '******'"; SqlCommand cmd = new SqlCommand(cmdtext, conn); cmd.ExecuteNonQuery(); } } //Email Alert to department staff who has been remove for Delegation Users user = Data_Users.GetUserInfo(Dg.Username); SendEmailNotification sen = new SendEmailNotification(); Department department = Data_Department.GetDepartmentInfoByID(user.DeptID_FK); String Useremail = user.EmailID; String EmailSubject = "Removed from Delegation"; String EmailBody = "<p> Dear " + user.Username + ",</p>"; EmailBody += "<p>You have been removed from InterimHead for " + department.Departmentname + "."; EmailBody += "<p>Thank you<br/>Logic University Staionery Store</p>"; EmailBody += "<p> Please do not reply to this email it is auto-generated.</p>"; sen.SendEmailHTML(Useremail, EmailSubject, EmailBody); return(RedirectToAction("ViewDelegations")); }
public HttpResponseMessage SaveRepresentative(string username) { String DepID = Data_Users.GetDepRepbyName(username); //getting DEP id of the Department Users u = Data_Users.GetUserInfo(username); Users DepRepInfo = Data_Users.GetDepRepInfo(DepID); int prev_DepRep = DepRepInfo.UserID; //Getting Previous Dep Rep ID int Confirm = Data_Users.AssignRepresentative(u.UserID); //Setting New Representative to Department if (Confirm != 0) { Data_Users.RemoveRepresentative(prev_DepRep); //Removing the Previous Representative of the Department } var message = Request.CreateResponse(HttpStatusCode.Created, "Successfully updated!"); return(message); }
public ActionResult Login(Users s, string ReturnUrl) { if (s.Username == null || s.Passcode == null) { return(View()); //display home screen } else { string Hash_Password = GetMD5Hash(s.Passcode); Users userinfo = Data_Users.GetUserInfo(s.Username); if (userinfo == null || userinfo.Passcode != Hash_Password) { Debug.WriteLine("I am lost here!"); return(View()); //display home screen } else { FormsAuthentication.SetAuthCookie(userinfo.Username, false); Session["UserID"] = userinfo.UserID; Session["DeptID"] = userinfo.DeptID_FK; Session["user"] = userinfo; } if (ReturnUrl != null) { return(Redirect(ReturnUrl)); } if (userinfo.role == "DepRep" || userinfo.role == "DepStaff" || userinfo.role == "DepHead" || userinfo.role == "InterimHead") { return(RedirectToAction("Home", "DepartmentRep", User)); } else { return(RedirectToAction("Home", "Supplier", User)); } } }