/// <summary>
 /// getting all projects from db
 /// </summary>
 /// <returns></returns>
 public IEnumerable<Project> GetAll()
 {
     using (AngularContext db = new AngularContext())
     {
         return db.Project.ToList();
     }
 }
 /// <summary>
 /// geting all tasks from db </summary>
 /// <returns></returns>
 public IEnumerable<Task> Get()
 {
     using (AngularContext db = new AngularContext())
     {
         return db.Tasks.ToList();
     }
 }
 /// <summary>
 /// Geting all Developers from db
 /// </summary>
 /// <returns></returns>
 public IEnumerable<Developer> GetAll()
 {
     using (AngularContext objDemoContext = new AngularContext())
     {
         return objDemoContext.Developer.ToList();
     }
 }
 /// <summary>
 /// Getting all features from db
 /// </summary>
 /// <returns></returns>
 public IEnumerable<Features> GetAll()
 {
     using (AngularContext db = new AngularContext())
     {
         return db.Features.ToList();
     }
 }
 /// <summary>
 /// Get one feature from db by ProjectId
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public IHttpActionResult Get(int id)
 {
     using (AngularContext db = new AngularContext())
     {
         var feature = db.Features.Where(a => a.ProjectId == id).ToList();
         return Ok(feature);
     }
 }
 /// <summary>
 /// get task from db by featureId
 /// </summary>
 /// <param name="featureId">From angular controller</param>
 /// <returns></returns>
 public IHttpActionResult Get(int featureId)
 {
     using (AngularContext db = new AngularContext())
     {
         var task = db.Tasks.Where(a => a.FeatureId == featureId).ToList();
         return Ok(task);
     }
 }
 public IHttpActionResult Post(Features feature)
 {
     using (AngularContext db = new AngularContext())
     {
         db.Features.Add(feature);
         db.SaveChanges();
     }
     return CreatedAtRoute("DefaultApi", new { Id = feature.FeatureId }, feature);
 }
 // POST api/<controller>
 /// <summary>
 /// post task to db
 /// </summary>
 /// <param name="task">From angular controller</param>
 /// <returns></returns>
 public IHttpActionResult Post(Task task)
 {
     using (AngularContext db = new AngularContext())
     {
         db.Tasks.Add(task);
         db.SaveChanges();
     }
     return CreatedAtRoute("DefaultApi", new { Id = task.TaskId }, task);
 }
 public IHttpActionResult Post(Project project)
 {
     using (AngularContext objDemoContext = new AngularContext())
     {
         objDemoContext.Project.Add(project);
         objDemoContext.SaveChanges();
     }
     return CreatedAtRoute("DefaultApi", new { Id = project.Id }, project);
 }
 public IHttpActionResult Post(Developer developer)
 {
     using (AngularContext objDemoContext = new AngularContext())
     {
         objDemoContext.Developer.Add(developer);
         objDemoContext.SaveChanges();
     }
     return CreatedAtRoute("DefaultApi", new { Id = developer.DeveloperId }, developer);
 }
 //GET/<controller>
 /// <summary>
 /// Getting one developer by DeveloperID
 /// </summary>
 /// <param name="id">From angular controller</param>
 /// <returns></returns>
 public IHttpActionResult Get(int id)
 {
     using (AngularContext objDemoContext = new AngularContext())
     {
         var employee = objDemoContext.Developer.FirstOrDefault(a => a.DeveloperId == id);
         if (employee != null)
         {
             return Ok(employee);
         }
         return NotFound();
     }
 }
 public IHttpActionResult Delete(int id)
 {
     using (AngularContext db = new AngularContext())
     {
         var getFeatures = db.Features.FirstOrDefault(a => a.FeatureId == id);
         if (getFeatures != null)
         {
             db.Features.Remove(getFeatures);
             db.SaveChanges();
             return Ok();
         }
         return NotFound();
     }
 }
 public IHttpActionResult Delete(int id)
 {
     using (AngularContext objDemoContext = new AngularContext())
     {
         var getEmployee = objDemoContext.Developer.FirstOrDefault(a => a.DeveloperId == id);
         if (getEmployee != null)
         {
             objDemoContext.Developer.Remove(getEmployee);
             objDemoContext.SaveChanges();
             return Ok();
         }
         return NotFound();
     }
 }
 public IHttpActionResult Delete(int id)
 {
     using (AngularContext objDemoContext = new AngularContext())
     {
         var getProject = objDemoContext.Project.FirstOrDefault(a => a.Id == id);
         if (getProject != null)
         {
             objDemoContext.Project.Remove(getProject);
             objDemoContext.SaveChanges();
             return Ok();
         }
         return NotFound();
     }
 }
 /// <summary>
 /// get one project from db by Id
 /// </summary>
 /// <param name="id">From angular controller</param>
 /// <returns></returns>
 public IHttpActionResult Get(int id)
 {
     using (AngularContext db = new AngularContext())
     {
         var project = db.Project.FirstOrDefault(a => a.Id == id);
         if (project != null)
         {
             return Ok(project);
         }
         else
         {
             return NotFound();
         }
     }
 }
 // DELETE api/<controller>/5
 /// <summary>
 /// delete task from db by TaskID
 /// </summary>
 /// <param name="id">From angular controller</param>
 /// <returns></returns>
 public IHttpActionResult Delete(int id)
 {
     using (AngularContext db = new AngularContext())
     {
         var getTask = db.Tasks.FirstOrDefault(a => a.TaskId == id);
         if (getTask != null)
         {
             db.Tasks.Remove(getTask);
             db.SaveChanges();
             return Ok();
         }
         else
         {
             return NotFound();
         }
     }
 }
        public IHttpActionResult Put(int id, Project project)
        {
            if (id != project.Id)
            {
                return BadRequest();
            }
            using (AngularContext contextObj = new AngularContext())
            {

                Project getProject = contextObj.Project.Find(id);
                getProject.Name = project.Name;
                contextObj.SaveChanges();
                return CreatedAtRoute("DefaultApi", new { Id = project.Id }, project);
            }
        }
        public IHttpActionResult Put(int id, Developer developer)
        {
            if (id != developer.DeveloperId)
            {
                return BadRequest();
            }
            using (AngularContext contextObj = new AngularContext())
            {
                Developer getEmployee = contextObj.Developer.Find(id);
                getEmployee.Name = developer.Name;
                getEmployee.Salary = developer.Salary;
                contextObj.SaveChanges();

                return CreatedAtRoute("DefaultApi", new { Id = developer.DeveloperId }, developer);
            }
        }
        /// <summary>
        /// Show main view
        /// </summary>
        /// <returns>Main View</returns>
        public ActionResult Index()
        {
            using (AngularContext db = new AngularContext())
            {
                //FIRST CHART
                var open = db.Tasks.Count(x => x.Open);
                var close = db.Tasks.Count(x => x.Open == false);
                //create a collection of data
                var transactionCounts = new List<Developer> {
                           new Developer(){  Name="Opened", Salary= open},
                           new Developer(){  Name="Closed", Salary=close},

                            };

                //modify data type to make it of array type
                var xDataMonths = transactionCounts.Select(i => i.Name).ToArray();
                var yDataCounts = transactionCounts.Select(i => new object[] { i.Salary }).ToArray();

                //instantiate an object of the Highcharts type
                var chart = new Highcharts("chart")
                    //define the type of chart
                            .InitChart(new Chart { DefaultSeriesType = ChartTypes.Pie })
                    //overall Title of the chart
                            .SetTitle(new Title { Text = "Opened task vs Closed task" })
                    //small label below the main Title
                            .SetSubtitle(new Subtitle { Text = DateTime.Now.ToShortDateString() })
                    //load the Y values
                            .SetSeries(new[]
                    {
                        new Series {Name = xDataMonths[0],Color = Color.Brown, Data = new Data(yDataCounts)},
                         new Series {Name = xDataMonths[1], Data = new Data(yDataCounts)}
                            //you can add more y data to create a second line
                            // new Series { Name = "Other Name", Data = new Data(OtherData) }
                    });

                List<Highcharts> chartList = new List<Highcharts>();
                chartList.Add(chart);

                //SECOND CHART
                var today = DateTime.Now.Date;
                var tasks = db.Tasks.Count(x => x.ClosingDate == today);
                var transactionCounts2 = new List<Developer>
                {
                    new Developer() {Name = "test", Salary=tasks }
                };
                object[] toCharts = transactionCounts2.Select(x => new object[] {x.Salary}).ToArray();
                var chart2 = new Highcharts("chart2")
                    //define the type of chart
                    .InitChart(new Chart { DefaultSeriesType = ChartTypes.Bar })
                    //overall Title of the chart
                    .SetTitle(new Title { Text = "Tasks closed Today" })
                    //small label below the main Title
                    .SetSubtitle(new Subtitle { Text = DateTime.Now.ToShortDateString() })
                    .SetSeries(new[]
                    {
                        new Series {Name = "Tasks closed Today", Data = new Data(toCharts)}
                    });

                chartList.Add(chart2);
                return View(chartList);
            }
        }
        public IHttpActionResult Put(int id, Features feature)
        {
            if (id != feature.FeatureId)
            {
                return BadRequest();
            }
            using (AngularContext db = new AngularContext())
            {
                Features getFeatures = db.Features.Find(id);
                getFeatures.FeatureName = feature.FeatureName;
                getFeatures.FeatureDescription = feature.FeatureDescription;
                db.SaveChanges();

                return CreatedAtRoute("DefaultApi", new { Id = feature.FeatureId }, feature);
            }
        }
        // PUT api/<controller>/5
        /// <summary>
        /// put task
        /// </summary>
        /// <param name="id">From angular controller</param>
        /// <param name="task">From angular controller</param>
        /// <returns></returns>
        public IHttpActionResult Put(int id, Task task)
        {
            if (id != task.FeatureId)
            {
                return BadRequest();
            }
            else
            {
                using (AngularContext db = new AngularContext())
                {
                    Task getTask = db.Tasks.Find(id);
                    getTask.FeatureId = task.FeatureId;
                    getTask.DeveloperId = task.DeveloperId;
                    getTask.Open = task.Open;
                    getTask.WorkLoad = task.WorkLoad;
                    getTask.Description = task.Description;
                    getTask.ClosingDate = task.ClosingDate;
                    db.SaveChanges();

                    return CreatedAtRoute("DefaultApi", new { Id = task.TaskId }, task);
                }
            }
        }