Example #1
0
        public void RenewRequest(Request request, Person person, DateTime startDate, DateTime endDate)
        {
            using (var context = new ProgDatabaseEntities())
            {
                Decision _newDecision = new Decision();
                Action   _renewAction = new Action();
                _renewAction = context.Actions.Where(a => a.DisplayName == "Renew").Single();

                _newDecision.Action1 = _renewAction;

                _newDecision.Request    = context.Requests.Where(r => r.RequestID == request.RequestID).Single();
                _newDecision.Person1    = context.People.Where(p => p.PersonID == person.PersonID).Single();
                _newDecision.ChangeDate = DateTime.Now;
                _newDecision.Reason     = "Renew initiated by " + person.ToString();

                context.Decisions.Add(_newDecision);

                DecisionLevel _newDecisionLevel = new DecisionLevel();
                _newDecisionLevel = context.DecisionLevels.Where(d => d.DecisionLevel1 == 1).Single();

                Request _request = new Request();
                _request = context.Requests.Where(r => r.RequestID == request.RequestID).Single();
                _request.DecisionLevel = _newDecisionLevel;
                _request.ValidityStart = startDate;
                _request.ValidityEnd   = endDate;

                context.SaveChanges();
            }
        }
Example #2
0
        public void AddNewRequest(Request request)
        {
            using (var context = new ProgDatabaseEntities())
            {
                var _person      = context.People.Where(p => p.PersonID == request.Person.PersonID).Single();
                var _role        = context.Roles.Where(r => r.RoleID == request.Role.RoleID).Single();
                var _requestType = context.RequestTypes.Where(rt => rt.RequestTypeID == 1).Single(); ////////// <----- TÖRÖLNI

                var _decisionLevel = context.DecisionLevels.Where(d => d.DecisionLevel1 == 1);

                request.Person      = _person;
                request.Role        = _role;
                request.RequestType = _requestType;



                foreach (var dLevel in _decisionLevel)
                {
                    request.DecisionLevel = dLevel;
                }

                context.Requests.Add(request);
                context.SaveChanges();
            }
        }
Example #3
0
        public void UpdateLocation(Location location, Person manager)
        {
            using (var context = new ProgDatabaseEntities())
            {
                Person oldLocManager = new Person();

                var loc = from l in context.Locations
                          where l.LocationID == location.LocationID
                          select l;

                var newManager = from m in context.People
                                 where m.PersonID == manager.PersonID
                                 select m;

                var _manager = context.Locations.Where(l => l.LocationID == location.LocationID).Single().People1;

                foreach (var item in _manager.ToList())
                {
                    _manager.Remove(item);
                }
                foreach (var m in newManager)
                {
                    _manager.Add(m);
                }
                context.SaveChanges();

                //var ujManager = context.Locations.Where(l => l.LocationID == location.LocationID).Single().People1;
            }
        }
Example #4
0
 public void AddNewPerson(Person person)
 {
     using (var context = new ProgDatabaseEntities())
     {
         context.People.Add(person);
         context.SaveChanges();
     }
 }
Example #5
0
 public void RemoveEditedPerson(Person person)
 {
     using (var context = new ProgDatabaseEntities())
     {
         try
         {
             context.Entry(person).State = EntityState.Deleted;
             context.SaveChanges();
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Example #6
0
        public void AddNewDecision(Person person, Request request)
        {
            using (var context = new ProgDatabaseEntities())
            {
                Decision newDecision = new Decision();
                var      _action     = context.Actions.Where(a => a.DisplayName.Contains("Create")).Single();
                //var decesionLevels = context.DecisionLevels.Where(d => d.DecisionLevel1 == 1);

                var _person  = context.People.Where(p => p.PersonID == person.PersonID).Single();
                var _request = context.Requests.Where(r => r.RequestID == request.RequestID).Single();

                newDecision.Request    = _request;
                newDecision.Person     = _person;
                newDecision.ChangeDate = DateTime.Now;
                newDecision.Reason     = "Request created by " + person;
                newDecision.Action1    = _action;
                context.Decisions.Add(newDecision);
                context.SaveChanges();
            }
        }
Example #7
0
        public void DenyRequest(Request request, Action action, Person approver, string reason)
        {
            using (var context = new ProgDatabaseEntities())
            {
                Decision _newDecision = new Decision();
                _newDecision.Action1    = context.Actions.Where(a => a.ActionID == action.ActionID).Single();
                _newDecision.Request    = context.Requests.Where(r => r.RequestID == request.RequestID).Single();
                _newDecision.Person1    = context.People.Where(p => p.PersonID == approver.PersonID).Single();
                _newDecision.ChangeDate = DateTime.Now;
                _newDecision.Reason     = reason;
                context.Decisions.Add(_newDecision);

                DecisionLevel _newDecisionLevel = new DecisionLevel();
                _newDecisionLevel = context.DecisionLevels.Where(d => d.DecisionLevel1 == 4).Single();

                Request _request = new Request();
                _request = context.Requests.Where(r => r.RequestID == request.RequestID).Single();
                _request.DecisionLevel = _newDecisionLevel;

                context.SaveChanges();
            }
        }
Example #8
0
        public void UpdatePerson(Person person)
        {
            using (var context = new ProgDatabaseEntities())
            {
                var query = from p in context.People
                            where p.PersonID == person.PersonID
                            select p;

                foreach (var item in query)
                {
                    item.FirstName  = person.FirstName;
                    item.LastName   = person.LastName;
                    item.Username   = person.Username;
                    item.Password   = person.Password;
                    item.Email      = person.Email;
                    item.Position   = person.Position;
                    item.LocationID = person.LocationID;
                    item.Manager    = person.Manager;
                }
                context.SaveChanges();
            }
        }
Example #9
0
        public void UnsubscribeRequest(Request request)
        {
            using (var context = new ProgDatabaseEntities())
            {
                try
                {
                    var decisions = from d in context.Decisions
                                    where d.RequestID == request.RequestID
                                    select d;

                    foreach (var decision in decisions)
                    {
                        context.Entry(decision).State = EntityState.Deleted;
                    }

                    context.Entry(request).State = EntityState.Deleted;
                    context.SaveChanges();
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }