public static void DeleteReview(User user, string UserID, int ServiceID) { Review r = GetReview(UserID, ServiceID); if (!user.isSystemAdmin && !(user.UserID == UserID)) throw new FaultException<SException>(new SException(), new FaultReason("Invalid User, User Does Not Have Rights To Delete Review!")); //chk if user can do this anot DAL dalDataContext = new DAL(); try { r = (from review in dalDataContext.reviews where review.UserID == UserID && review.ServiceID == ServiceID select review).FirstOrDefault(); dalDataContext.reviews.DeleteOnSubmit(r); dalDataContext.SubmitChanges(); } catch { throw new FaultException<SException>(new SException(), new FaultReason("An Error occured While Deleting Review, Please Try Again!")); } }
public static void AddFieldAnswer(int FieldID, int ParticipantID, string Answer, DAL dalDataContext) { try { //Event evnt = EventController.GetEvent(EventID); //if(e == null) // throw new FaultException<SException>(new SException(), // new FaultReason("Invalid Event ID")); FieldAnswer fa = GetFieldAnswer(ParticipantID, FieldID); //DAL dalDataContext = new DAL(); Table<FieldAnswer> fieldAnswers = dalDataContext.fieldAnswer; if (fa == null) { FieldAnswer CreateFieldAns = new FieldAnswer(ParticipantID, FieldID, Answer); fieldAnswers.InsertOnSubmit(CreateFieldAns); fieldAnswers.Context.SubmitChanges(); } else { fa.Answer = Answer; dalDataContext.SubmitChanges(); } } catch { throw new FaultException<SException>(new SException(), new FaultReason("An Error occured While Adding New Field Answer, Please Try Again!")); } }
public static void DeleteProgram(User user, int ProgramID) { //chk if user got rights or is organizer Program P = GetPrograms(ProgramID); if (!user.isAuthorized(EventController.GetEvent(P.EventID), EnumFunctions.Delete_Programmes)) throw new FaultException<SException>(new SException(), new FaultReason("Invalid User, User Does Not Have Rights To Delete Programs!")); DAL dalDataContext = new DAL(); try { Program matchedprograms = (from programs in dalDataContext.programs where programs.ProgramID == P.ProgramID select programs).FirstOrDefault(); dalDataContext.programs.DeleteOnSubmit(matchedprograms); dalDataContext.SubmitChanges(); } catch (Exception ex) { throw new FaultException<SException>(new SException(ex.Message), new FaultReason("An Error occured While Adding Deleting Program, Please Try Again!")); //throw exception here } }
//Delete the task public static void DeleteTask(User user, int TaskID, int eventID) { Task taskToDelete = GetTask(TaskID); //TODO: Put in after roles management for task up if (!user.isAuthorized(EventController.GetEvent(taskToDelete.EventID), EnumFunctions.Delete_Task)) throw new FaultException<SException>(new SException(), new FaultReason("Invalid User, User Does Not Have Rights To Delete Tasks!")); DAL dalDataContext = new DAL(); try { Task matchedTask = (from tasks in dalDataContext.tasks where tasks.TaskID == taskToDelete.TaskID && tasks.EventID == taskToDelete.EventID select tasks).FirstOrDefault(); dalDataContext.tasks.DeleteOnSubmit(matchedTask); dalDataContext.SubmitChanges(); } catch { throw new FaultException<SException>(new SException(), new FaultReason("An Error occured While Deleting Guest, Please Try Again!")); } }
public static void DeleteGuest(User user, int GuestID) { //chk if user can do this anot Guest g = GetGuest(GuestID); if (!user.isAuthorized(EventController.GetEvent(g.EventID), EnumFunctions.Delete_Guest)) throw new FaultException<SException>(new SException(), new FaultReason("Invalid User, User Does Not Have Rights To Delete Guest!")); DAL dalDataContext = new DAL(); try { Guest matchedguest = (from guests in dalDataContext.guests where guests.GuestId == g.GuestId select guests).FirstOrDefault(); dalDataContext.guests.DeleteOnSubmit(matchedguest); dalDataContext.SubmitChanges(); } catch { throw new FaultException<SException>(new SException(), new FaultReason("An Error occured While Deleting Guest, Please Try Again!")); } }
public static void AddDefaultFeids(int EventID, DAL dalDataContext) { List<Field> ListField = new List<Field>(); Field firstName = new Field(); firstName.FieldName = firstName.FieldLabel = "First Name"; Field lastName = new Field(); lastName.FieldName = lastName.FieldLabel = "Last Name"; firstName.IsRequired = lastName.IsRequired = true; Field email = new Field(); email.FieldName = email.FieldLabel = "Email"; email.IsRequired = email.IsRequired = true; ListField.Add(firstName); ListField.Add(lastName); ListField.Add(email); try { for (int i = 0; i < ListField.Count; i++) { AddField(dalDataContext, EventID, ListField[i]); } dalDataContext.SubmitChanges(); } catch (Exception ex) { throw new FaultException<SException>(new SException(), new FaultReason("An Error occured While Adding New Field, Please Try Again!")); } }
public static void deleteItem(User user, Items iten) { if (!user.isAuthorized( EventController.GetEvent(iten.EventID), EnumFunctions.Manage_Items)) throw new FaultException<SException>(new SException(), new FaultReason("Invalid User, User Does Not Have Rights To Delete Item!")); DAL dalDataContext = new DAL(); try { Items matchedItem = (from item in dalDataContext.items where item.typeString == iten.typeString && item.EventID == iten.EventID && item.ItemName == iten.ItemName select item).FirstOrDefault<Items>(); dalDataContext.items.DeleteOnSubmit(matchedItem); dalDataContext.SubmitChanges(); } catch { throw new FaultException<SException>(new SException(), new FaultReason("An Error occured While Deleting Item , Please Try Again!")); } }
//if existing then return the existing otp public static string CreateNewRequestee(string targetEmail) { DAL dalDataContext = new DAL(); try { Table<Requestee> requestees = dalDataContext.requestees; Requestee existingRequestee = (from requestee in dalDataContext.requestees where requestee.TargetEmail.ToLower() == targetEmail.ToLower() select requestee).SingleOrDefault<Requestee>(); if (existingRequestee == null) { string otp = OTPGenerator.Generate(); Requestee newRequestee = new Requestee(targetEmail,otp); dalDataContext.requestees.DeleteOnSubmit(newRequestee); dalDataContext.SubmitChanges(); return otp; } else { return existingRequestee.Otp; } } catch (Exception ex) { throw new FaultException<SException>(new SException(ex.Message), new FaultReason("An Error occured While Creating New Requestee: " + ex.Message)); } }
public static void AddService(User user, int EventID, string Address, string name, string url, string notes) { bool allow = false; if (user.isSystemAdmin || user.isEventOrganizer) { allow = true; } if (!allow) { if (!user.isAuthorized(EventController.GetEvent(EventID), EnumFunctions.Manage_Items)) throw new FaultException<SException>(new SException(), new FaultReason("Invalid User, User Does Not Have Rights To Edit this Service!")); } try { DAL dalDataContext = new DAL(); Table<Service> services = dalDataContext.services; Service creatingService = new Service(Address, name, url, notes); services.InsertOnSubmit(creatingService); services.Context.SubmitChanges(); dalDataContext.SubmitChanges(); } catch { throw new FaultException<SException>(new SException(), new FaultReason("An Error occured While Adding New Service, Please Try Again!")); } }
public static void CancelRequest(User user, int requestID) { Events evnt = EventController.GetEvent(GetRequest(requestID).EventID); if (!user.isAuthorized(evnt, EnumFunctions.Manage_Requests)) throw new FaultException<SException>(new SException(), new FaultReason("Invalid User, User Does Not Have Rights To Cancel Request!")); DAL dalDataContext = new DAL(); Request request = (from requests in dalDataContext.requests where requests.RequestID == requestID select requests).FirstOrDefault(); if (request == null) { throw new FaultException<SException>(new SException(), new FaultReason("Invalid Request")); } else { Events e = EventController.GetEvent(request.EventID); if (e.Organizerid != user.UserID) // Manage Requests, View Requests User.isAuthorized( throw new FaultException<SException>(new SException(), new FaultReason("Invalid User, User Does Not Have Rights To Edit This Request!")); request.Status = RequestStatus.Cancelled; dalDataContext.SubmitChanges(); RequestLogController.InsertRequestLog(request); } }
public static void DeleteParticipant(User user, int ParticipantID) { try { DAL dalDataContext = new DAL(); // Participant p = GetParticipant(ParticipantID); Participant p = (from participants in dalDataContext.participants where participants.ParticipantID == ParticipantID select participants).SingleOrDefault<Participant>(); //chk if user can do this anot if (!user.isAuthorized(EventController.GetEvent(p.EventID), EnumFunctions.Manage_Participant)) goto Error; dalDataContext.participants.DeleteOnSubmit(p); dalDataContext.SubmitChanges(); } catch { throw new FaultException<SException>(new SException(), new FaultReason("An Error occured While Deleting Participant, Please Try Again!")); } return; Error: throw new FaultException<SException>(new SException(), new FaultReason("Invalid User, User Does Not Have Rights To Delete Participant!")); }
public static void DeleteAllParticipant(int EventID, DAL dalDataContext) { //chk if user can do this anot try { // Participant p = GetParticipant(ParticipantID); List<Participant> participants = (from participant in dalDataContext.participants where participant.EventID == EventID select participant).ToList<Participant>(); for (int i = 0; i < participants.Count; i++) { dalDataContext.participants.DeleteOnSubmit(participants[i]); } dalDataContext.SubmitChanges(); } catch { throw new FaultException<SException>(new SException(), new FaultReason("An Error occured While Clearing Participant, Please Try Again!")); } return; }
public static void SetBought(User user, Items iten) { //if (!user.isAuthorized(user, EventController.GetEvent(iten.EventID), EnumFunctions.Manage_Items)) // throw new FaultException<SException>(new SException(), // new FaultReason("Invalid User, User Does Not Have Rights To Update Items properties!")); try { DAL dalDataContext = new DAL(); OptimizedBudgetItemsDetails matchedItem = (from item in dalDataContext.optimizedBudgetItemDetails where item.typeString == iten.typeString && item.EventID == iten.EventID && item.ItemName == iten.ItemName select item).FirstOrDefault<OptimizedBudgetItemsDetails>(); if (matchedItem == null) { throw new FaultException<SException>(new SException(), new FaultReason("Invalid Item ")); } else { matchedItem.IsBought = true; dalDataContext.SubmitChanges(); } } catch { throw new FaultException<SException>(new SException(), new FaultReason("An Error occured While Updating Item, Please Try Again!")); } }
public static void DeleteEvent(User user, int EventID) { //chk if user can do this anot Events evnt = GetEvent(EventID); if (!user.isAuthorized(evnt)) throw new FaultException<SException>(new SException(), new FaultReason("Invalid User, User Does Not Have Rights To Delete this Events!")); DAL dalDataContext = new DAL(); try { Events matchedevent = (from events in dalDataContext.events where events.EventID == evnt.EventID //events.Organizerid == user.userID select events).FirstOrDefault(); dalDataContext.events.DeleteOnSubmit(matchedevent); dalDataContext.SubmitChanges(); } catch { throw new FaultException<SException>(new SException(), new FaultReason("An Error occured While Deleting Event, Please Try Again!")); } }
private static void RemoveExistingBudget(int eventID) { DAL dalDataContext = new DAL(); OptimizedBudgetItems matchedBudget = (from bgt in dalDataContext.optimizedBudgetItems where bgt.EventID == eventID orderby bgt.GeneratedDate descending select bgt).FirstOrDefault<OptimizedBudgetItems>(); if (matchedBudget != null) { dalDataContext.optimizedBudgetItems.DeleteOnSubmit(matchedBudget); dalDataContext.SubmitChanges(); //Child will automatically be deleted due to cascade from sql } }
public static bool AddFacilityAdmin(SystemAdmin assigner, string useridToAssign, Faculties f) { if (assigner.UserID == useridToAssign) { throw new FaultException<SException>(new SException(), new FaultReason("You cannot Remove your own role!")); } else { RemoveAllRoles(useridToAssign); //Remove existing role DAL dalDataContext = new DAL(); try { FacilityAdmin fa = (from facAdm in dalDataContext.facAdmins where facAdm.Faculty == f select facAdm).FirstOrDefault<FacilityAdmin>(); if (fa == null) { Table<FacilityAdmin> sTable = dalDataContext.facAdmins; fa = new FacilityAdmin(useridToAssign, f); sTable.InsertOnSubmit(fa); sTable.Context.SubmitChanges(); } else { fa.UserID = useridToAssign; dalDataContext.SubmitChanges(); } string msg = assigner.Name + " has assigned you to the role of Facility Admin for " + f.ToString().Replace("_", " "); string title = "You have been Added to the System Group - Facility Administrator"; NotificationController.sendNotification(assigner.UserID, useridToAssign, title, msg); return true; } catch (Exception) { throw new FaultException<SException>(new SException(), new FaultReason("An Error occured while the system is Adding the user's role, Please Try Again!")); } } }
//if existing then return the existing otp public static void InsertRequestLog(Request r) { try { DAL dalDataContext = new DAL(); Table<RequestLog> requestLogs = dalDataContext.requestLogs; RequestLog newRequestLog = new RequestLog(r.RequestID, r.Description, r.Remark, r.Status, r.URL); dalDataContext.requestLogs.InsertOnSubmit(newRequestLog); dalDataContext.SubmitChanges(); } catch (Exception ex) { throw new FaultException<SException>(new SException(ex.Message), new FaultReason("An Error occured While Creating New Requestee: " + ex.Message)); } }
public static void DeleteRole(User user, int RoleID) { DAL dalDataContext = new DAL(); try { Role matchedrole = (from roles in dalDataContext.roles where roles.RoleID == RoleID select roles).FirstOrDefault(); dalDataContext.roles.DeleteOnSubmit(matchedrole); dalDataContext.SubmitChanges(); } catch { throw new FaultException<SException>(new SException(), new FaultReason("An Error occured While Deleting Role, Please Try Again!")); } }
//to approve or reject public static void ChangeStatus(Requestee requestee, int requestID, RequestStatus status, string remark) { DAL dalDataContext = new DAL(); try { Request request = (from requests in dalDataContext.requests where requests.RequestID == requestID && requests.TargetEmail.Equals(requests.TargetEmail) select requests).FirstOrDefault(); if (request == null) { throw new FaultException<SException>(new SException(), new FaultReason("Invalid Request")); } else if (!request.TargetEmail.Equals(requestee.TargetEmail, StringComparison.CurrentCultureIgnoreCase)) { throw new FaultException<SException>(new SException(), new FaultReason("You are not authorized to perform this task")); } else { if (status == RequestStatus.Cancelled || status == RequestStatus.Pending) { throw new FaultException<SException>(new SException(), new FaultReason("You can either approve or reject the request!")); } request.Status = status; request.Remark = remark; dalDataContext.SubmitChanges(); RequestLogController.InsertRequestLog(request); } } catch (Exception ex) { throw new FaultException<SException>(new SException(ex.Message), new FaultReason("An Error occured While Updating Request: " + ex.Message)); } }
//public static FieldAnswer GetFieldAnswer(int participantID, int FieldID, DAL dalDataContext) //{ // try // { // //DAL dalDataContext = new DAL(); // FieldAnswer existingFieldAnswer = (from fieldAnswer in dalDataContext.fieldAnswer // where fieldAnswer.ParticipantID == participantID && // fieldAnswer.FieldID == FieldID // select fieldAnswer).FirstOrDefault(); // if (existingFieldAnswer == null) // { // throw new FaultException<SException>(new SException(), // new FaultReason("Invalid Field Answer")); // } // return existingFieldAnswer; // } // catch // { // throw new FaultException<SException>(new SException(), // new FaultReason("An Error occured While Retrieving Field Answer Data, Please Try Again!")); // } //} public static void DeleteFieldAnswer(User user, int participantID, int FieldID) { //if (!u.isAuthorized(u, EventController.GetEvent(FieldController.GetField(FieldID).EventID), EnumFunctions.Add_Guest)) // throw new FaultException<SException>(new SException(), // new FaultReason("Invalid User, User Does Not Have Rights To Delete Field Answer!")); //chk if user can do this anot DAL dalDataContext = new DAL(); try { FieldAnswer fa = GetFieldAnswer(participantID, FieldID); dalDataContext.fieldAnswer.DeleteOnSubmit(fa); dalDataContext.SubmitChanges(); } catch { throw new FaultException<SException>(new SException(), new FaultReason("An Error occured While Deleting Field Answer, Please Try Again!")); } }
public static void DeleteDay(EventDay d) { //chk if user can do this anot DAL dalDataContext = new DAL(); try { EventDay matchedday = (from days in dalDataContext.days where days.DayID == d.DayID select days).FirstOrDefault(); dalDataContext.days.DeleteOnSubmit(matchedday); dalDataContext.SubmitChanges(); } catch (Exception ex) { throw new FaultException<SException>(new SException(ex.Message), new FaultReason("An Error occured While Deleting Day, Please Try Again!")); } }
public static void deleteAllNotifications(User user, string uid) { if (String.Compare(user.UserID, uid, true) != 0) throw new FaultException<SException>(new SException(), new FaultReason("Invalid User, You cannot delete message not in your inbox")); try { DAL dalDataContext = new DAL(); List<Notifications> matchingNotif = (from notif in dalDataContext.notifications where notif.Receiver == user.UserID select notif).ToList<Notifications>(); dalDataContext.notifications.DeleteAllOnSubmit(matchingNotif); dalDataContext.SubmitChanges(); } catch (Exception ex) { throw new FaultException<SException>(new SException(), new FaultReason(ex.Message)); } }
public static void DeleteFile(User user, int eventID, string folderName, string fileName) { Events evnt = EventController.GetEvent(eventID); DAL dalDataContext = new DAL(); try { WorkspaceFiles matchedWS = (from wsf in dalDataContext.ArtefactWSFiles where wsf.EventID == eventID && wsf.FolderName.ToLower() == folderName.ToLower() && wsf.FileName.ToLower() == fileName.ToLower() select wsf).FirstOrDefault(); if (matchedWS != null) { //TODO: Add Enum CreateArtefactFolder in functions - Nick if (user.UserID.Equals(matchedWS.UploadedBy, StringComparison.CurrentCultureIgnoreCase) || RoleLogicController.HaveRights(evnt, user, EnumFunctions.Manage_Artefacts)) //user.isAuthorized(evnt, ManageArtefact) after enum f(x) up { dalDataContext.ArtefactWSFiles.DeleteOnSubmit(matchedWS); dalDataContext.SubmitChanges(); } else { throw new FaultException<SException>(new SException(), new FaultReason("You cannot delete the file that is not uploaded by you!")); } } } catch (Exception ex) { throw new FaultException<SException>(new SException(ex.Message), new FaultReason("An Error occured While Deleting Workspace Files, Please Try Again!")); } }
public static void RemoveFacility(User user, string locID, Faculties fac) { if (!user.isFacilityAdmin) { throw new FaultException<SException>(new SException(), new FaultReason("Invalid User, User Does Not Have Rights To Remove Facility!")); } DAL dalDataContext = new DAL(); try { Facility f = (from faci in dalDataContext.Facilities where faci.FacilityID == locID && faci.Faculty == fac select faci).FirstOrDefault(); if (f != null) { if ((user.isSystemAdmin) || (f.Faculty == user.UserFaculty)) { dalDataContext.Facilities.DeleteOnSubmit(f); dalDataContext.SubmitChanges(); } else if (f.Faculty != user.UserFaculty) { if (!user.isSystemAdmin) throw new FaultException<SException>(new SException(), new FaultReason("You do not belong to the faculty of the facility!")); } } } catch (Exception ex) { throw new FaultException<SException>(new SException(ex.Message), new FaultReason("An Error occured while deleting the facility, Please Try Again!")); } }
public static void deleteItemType(User user, ItemTypes type) { if (!user.isAuthorized( EventController.GetEvent(type.EventID), EnumFunctions.Manage_ItemTypes)) throw new FaultException<SException>(new SException(), new FaultReason("Invalid User, User Does Not Have Rights To Delete Guest!")); DAL dalDataContext = new DAL(); try { ItemTypes itemType = (from iType in dalDataContext.itemTypes where iType.EventID == type.EventID && iType.typeString == type.typeString select iType).FirstOrDefault<ItemTypes>(); dalDataContext.itemTypes.DeleteOnSubmit(itemType); dalDataContext.SubmitChanges(); } catch { throw new FaultException<SException>(new SException(), new FaultReason("An Error occured While Deleting Item Type, Please Try Again!")); } }
public static void DeleteBudgetIncome(User user, int BudgetIncomeID, int eventID) { if (!user.isAuthorized(EventController.GetEvent(eventID), EnumFunctions.Manage_Income)) throw new FaultException<SException>(new SException(), new FaultReason("Invalid User, User Does Not Have Rights To Delete Income!")); DAL dalDataContext = new DAL(); try { BudgetIncome matchedincome = (from income in dalDataContext.income where income.IncomeID == BudgetIncomeID && income.EventID == eventID select income).FirstOrDefault(); dalDataContext.income.DeleteOnSubmit(matchedincome); dalDataContext.SubmitChanges(); } catch { throw new FaultException<SException>(new SException(), new FaultReason("An Error occured While Deleting Income, Please Try Again!")); } }
//need edit public static void DeleteService(User user, int serviceID) { if (!user.isSystemAdmin && !user.isEventOrganizer) throw new FaultException<SException>(new SException(), new FaultReason("Invalid User, User Does Not Have Rights To Delete Service!")); //chk if user can do this anot DAL dalDataContext = new DAL(); try { Service s = (from service in dalDataContext.services where service.ServiceID == serviceID select service).FirstOrDefault(); dalDataContext.services.DeleteOnSubmit(s); dalDataContext.SubmitChanges(); } catch { throw new FaultException<SException>(new SException(), new FaultReason("An Error occured While Deleting service, Please Try Again!")); } }
public static void deleteNotification(User user, Notifications msg) { if (String.Compare(user.UserID, msg.Receiver, true) != 0) throw new FaultException<SException>(new SException(), new FaultReason("Invalid User, You cannot delete message not in your inbox")); DAL dalDataContext = new DAL(); try { Notifications matchingNotif = (from notif in dalDataContext.notifications where notif.Sender == msg.Sender && notif.Receiver == user.UserID && notif.SendDateTime == msg.SendDateTime select notif).Single<Notifications>(); dalDataContext.notifications.DeleteOnSubmit(matchingNotif); dalDataContext.SubmitChanges(); } catch (Exception ex) { throw new FaultException<SException>(new SException(), new FaultReason(ex.Message)); } }
public static void DeletePointOfContact(User user, int PointOfContactID) { if (!user.isSystemAdmin && !user.isEventOrganizer) throw new FaultException<SException>(new SException(), new FaultReason("Invalid User, User Does Not Have Rights To Delete Point Of Contact!")); //chk if user can do this anot DAL dalDataContext = new DAL(); try { PointOfContact poc = (from pointOfContact in dalDataContext.pointOfContacts where pointOfContact.PointOfContactID == PointOfContactID select pointOfContact).FirstOrDefault(); dalDataContext.pointOfContacts.DeleteOnSubmit(poc); dalDataContext.SubmitChanges(); } catch { throw new FaultException<SException>(new SException(), new FaultReason("An Error occured While Deleting Point Of Contact, Please Try Again!")); } }
public static void setItemTypeImportance(User user, ItemTypes type, bool isImpt) { if (!user.isAuthorized( EventController.GetEvent(type.EventID), EnumFunctions.Manage_ItemTypes)) throw new FaultException<SException>(new SException(), new FaultReason("Invalid User, User Does Not Have Rights To Edit this Guest!")); try { DAL dalDataContext = new DAL(); ItemTypes matchedItem = (from iten in dalDataContext.itemTypes where iten.EventID == type.EventID && iten.typeString == type.typeString select iten).FirstOrDefault<ItemTypes>(); if (matchedItem == null) { throw new FaultException<SException>(new SException(), new FaultReason("Invalid Item Type")); } else { matchedItem.IsImportantType = isImpt; dalDataContext.SubmitChanges(); } } catch { throw new FaultException<SException>(new SException(), new FaultReason("An Error occured While Updating Item Type, Please Try Again!")); } }