コード例 #1
0
        public JsonResult DeleteEmployee(int employeeID)
        {
            ResourceEventContext db = new ResourceEventContext();

            db.Configuration.ProxyCreationEnabled = false;
            var status = false;

            List <Event> empEvent = new List <Event>();

            //Finds event by ID which should be deleted
            var emp = db.Employees.Where(a => a.EmployeeID == employeeID).FirstOrDefault();

            if (emp != null)
            {
                //Removes events connected to Employee from DB
                if (db.Events.Where(x => x.EmployeeID == employeeID).Any())
                {
                    empEvent = db.Events.Where(x => x.EmployeeID == employeeID).ToList();
                    foreach (Event tempev in empEvent)
                    {
                        db.Events.Remove(tempev);
                    }
                    empEvent.Clear();
                }


                db.Employees.Remove(emp);
                db.SaveChanges();
                status = true;
            }

            return(new JsonResult {
                Data = new { status = status }
            });
        }
コード例 #2
0
        public JsonResult SaveEmployee(Employee emp)
        {
            ResourceEventContext db = new ResourceEventContext();

            db.Configuration.ProxyCreationEnabled = false;
            var status = false;

            //If the event ID is bigger than zero its a existing event.
            if (emp.EmployeeID > 0)
            {
                //Grabs event with given ID from the database
                var oldEvent = db.Employees.Where(a => a.EmployeeID == emp.EmployeeID).FirstOrDefault();

                if (oldEvent != null)
                {
                    //Replaces fields that has been updated
                    oldEvent.FirstName  = emp.FirstName;
                    oldEvent.LastName   = emp.LastName;
                    oldEvent.Occupation = emp.Occupation;
                    oldEvent.EmployeeID = emp.EmployeeID;
                }
            }
            //If a new event is added, it just adds the new event to DB
            else
            {
                db.Employees.Add(emp);
            }

            db.SaveChanges();
            status = true;

            return(new JsonResult {
                Data = new { status = status }
            });
        }
コード例 #3
0
        public JsonResult DeleteEvent(int eventID)
        {
            ResourceEventContext db = new ResourceEventContext();

            db.Configuration.ProxyCreationEnabled = false;
            var status = false;

            //Finds event by ID which should be deleted
            var evnt = db.Events.Where(a => a.EventID == eventID).FirstOrDefault();

            if (evnt != null)
            {
                //Removes event from DB
                db.Events.Remove(evnt);
                db.SaveChanges();
                status = true;
            }

            return(new JsonResult {
                Data = new { status = status }
            });
        }
コード例 #4
0
        public JsonResult SaveEvent(Event evnt)
        {
            ResourceEventContext db = new ResourceEventContext();

            db.Configuration.ProxyCreationEnabled = false;
            var status = false;

            //If the event ID is bigger than zero its a existing event.
            if (evnt.EventID > 0)
            {
                //Grabs event with given ID from the database
                var oldEvent = db.Events.Where(a => a.EventID == evnt.EventID).FirstOrDefault();

                if (oldEvent != null)
                {
                    //Replaces fields that has been updated
                    oldEvent.EventID     = evnt.EventID;
                    oldEvent.EmployeeID  = evnt.EmployeeID;
                    oldEvent.Title       = evnt.Title;
                    oldEvent.Start       = evnt.Start;
                    oldEvent.End         = evnt.End;
                    oldEvent.IsFullDay   = evnt.IsFullDay;
                    oldEvent.Description = evnt.Description;
                    oldEvent.ThemeColor  = evnt.ThemeColor;
                }
            }
            //If a new event is added, it just adds the new event to DB
            else
            {
                db.Events.Add(evnt);
            }

            db.SaveChanges();
            status = true;

            return(new JsonResult {
                Data = new { status = status }
            });
        }