public async Task <ActionResult> DeleteConfirmed(int id)
        {
            HourRecord hourRecord = await db.HourRecords.FindAsync(id);

            db.HourRecords.Remove(hourRecord);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
 public void GetMinuteListShouldThrowNotSupportedExceptionGivenCompleteAdding()
 {
     try
     {
         var hourRecord = new HourRecord(1);
         hourRecord.CompleteAdding();
         hourRecord.GetMinuteList();
         Assert.Fail("Expected Exception");
     }
     catch (NotSupportedException)
     {
     }
     Assert.Pass();
 }
        // GET: HourRecords/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HourRecord hourRecord = await db.HourRecords.FindAsync(id);

            if (hourRecord == null)
            {
                return(HttpNotFound());
            }
            return(View(hourRecord));
        }
        public async Task <ActionResult> Edit([Bind(Include = "HourRecordID,DateTime,Hours,Employee_EmployeeID,Job_JobID,Comment")] HourRecord hourRecord)
        {
            if (ModelState.IsValid)
            {
                db.Entry(hourRecord).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.Job_JobID           = new SelectList(db.Jobs, "JobID", "JobName", hourRecord.Job_JobID);
            ViewBag.Employee_EmployeeID = new SelectList(db.Employees, "EmployeeID", "FirstName", hourRecord.Employee_EmployeeID);

            return(View(hourRecord));
        }
Exemplo n.º 5
0
        public void GetMinuteListShouldUpdateMissingMinutes()
        {
            var data = new TestIncomingRecordData()
            {
                CpuLoad = 100, LoadedDateTime = DateTime.Now
            };
            var testDate = data.LoadedDateTime;

            var hourRecord = new HourRecord(testDate.Hour);

            data.CpuLoad        = 300;
            data.LoadedDateTime = data.LoadedDateTime.Subtract(new TimeSpan(0, 0, 4, 0));
            hourRecord.Update(data);
            Assert.That(hourRecord.GetMinuteList().Item1.Count, Is.EqualTo(6));
        }
Exemplo n.º 6
0
        public void Post(string name, string weekBeginning, string weekEnd, int workedHours)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                using (Stream stream = response.GetResponseStream())

                    using (StreamReader jsonStream = new StreamReader(stream))
                    {
                        HourRecord hourRecord = new HourRecord
                        {
                            Name          = name,
                            WeekBeginning = weekBeginning,
                            WeekEnd       = weekEnd,
                            WorkedHours   = workedHours
                        };

                        var            jsonOld = jsonStream.ReadToEnd();
                        DataBaseStruct list    = JsonConvert.DeserializeObject <DataBaseStruct>(jsonOld);
                        list.HourRecords.Add(hourRecord);

                        //Serializar el json
                        var request2 = (HttpWebRequest)WebRequest.Create(url);
                        request2.Method      = "POST";
                        request2.ContentType = "application/json";
                        request2.Timeout     = 30000;
                        string jsonNew   = JsonConvert.SerializeObject(list);
                        byte[] byteArray = Encoding.UTF8.GetBytes(jsonNew);
                        request2.ContentLength = byteArray.Length;

                        using (var dataStream = request2.GetRequestStream())
                        {
                            dataStream.Write(byteArray, 0, byteArray.Length);
                        }

                        using (HttpWebResponse response3 = (HttpWebResponse)request2.GetResponse())
                        {
                            using (Stream stream2 = response3.GetResponseStream())
                            {
                                using (StreamReader reader = new StreamReader(stream2))
                                {
                                    string responseFromServer = reader.ReadToEnd();
                                }
                            }
                        }
                    }
        }
Exemplo n.º 7
0
        public void UpdateShouldUpdateMinutes()
        {
            var data = new IncomingRecordData()
            {
                CpuLoad = 100
            };
            var testDate = data.LoadedDateTime;

            var hourRecord = new HourRecord(testDate.Hour);

            hourRecord.Update(data);
            Assert.That(hourRecord.GetMinuteList().Item1, Is.EqualTo(100));

            data.CpuLoad = 300;
            hourRecord.Update(data);
            Assert.That(hourRecord.GetMinuteList().Item1, Is.EqualTo(200));
        }
        // GET: HourRecords/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HourRecord hourRecord = await db.HourRecords.FindAsync(id);

            var hourTracker = from h in db.HourRecords.Include(h => h.Employee).Include(h => h.Job)
                              where h.HourRecordID == id.Value
                              select h;

            if (hourRecord == null)
            {
                return(HttpNotFound());
            }
            return(View(hourRecord));
        }
        public async Task <ActionResult> Create([Bind(Include = "HourRecordID,DateTime,Hours,Employee_EmployeeID,Job_JobID,Comment")] HourRecord hourRecord)
        {
            ApplicationDbContext context = new ApplicationDbContext();
            //used to see who is currently logged in
            UserManager <ApplicationUser> UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));
            ApplicationUser currentUser = UserManager.FindById(User.Identity.GetUserId());

            if (ModelState.IsValid)
            {
                hourRecord.Employee_EmployeeID = currentUser.Employee_EmployeeID;
                db.HourRecords.Add(hourRecord);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            //Possibly adding again for admin use?
            //ViewBag.Employee_EmployeeID = new SelectList(db.Employees, "EmployeeID", "FirstName", hourRecord.Employee_EmployeeID);

            return(View(hourRecord));
        }
        // GET: HourRecords/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HourRecord hourRecord = await db.HourRecords.FindAsync(id);

            var hourTracker = from h in db.HourRecords.Include(h => h.Employee)
                              where h.HourRecordID == id.Value
                              select h;

            if (hourRecord == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Job_JobID           = new SelectList(db.Jobs, "JobID", "JobName", hourRecord.Job_JobID);
            ViewBag.Employee_EmployeeID = new SelectList(db.Employees, "EmployeeID", "FirstName", hourRecord.Employee_EmployeeID);

            return(View(hourRecord));
        }