예제 #1
0
        public ActionResult Create([Bind(Exclude = "MaChuyen")] BangTheoDoiToCat bangTheoDoiToCat)
        {
            if (ModelState.IsValid)
            {
                _context.BangTheoDoiToCats.Add(bangTheoDoiToCat);
                _context.SaveChanges();
            }

            return(Json(bangTheoDoiToCat, JsonRequestBehavior.AllowGet));
        }
예제 #2
0
        public ActionResult Create([Bind(Include = "MaChuyen,MaHang,SLKeHoach,ThucHien,LuyKeThucHien,DenBaoCapBTP")] BangTheoDoiToCat bangTheoDoiToCat)
        {
            if (ModelState.IsValid)
            {
                db.BangTheoDoiToCats.Add(bangTheoDoiToCat);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.MaHang = new SelectList(db.BangTenMatHangs, "MaHang", "TenHang", bangTheoDoiToCat.MaHang);
            return(View(bangTheoDoiToCat));
        }
예제 #3
0
        public ActionResult Edit(int userId, User user)
        {
            var context = new TrackerDbContext();

            if (ModelState.IsValid)
            {
                User userToEdit = context.Users.Where(x => x.Id == userId).FirstOrDefault();
                userToEdit.FirstName   = user.FirstName;
                userToEdit.Lastname    = user.Lastname;
                userToEdit.Login       = user.Login;
                userToEdit.PhoneNumber = user.PhoneNumber;
                userToEdit.Email       = user.Email;
                userToEdit.CompanyId   = user.CompanyId;
                userToEdit.UserTypeId  = userToEdit.UserTypeId;
                context.SaveChanges();
                return(RedirectToAction("List"));
            }
            CreateUserViewModel userViewModel = new CreateUserViewModel
            {
                Companies = context.Companies.ToList(),
                UserTypes = context.UserTypes.ToList(),
                User      = context.Users.Where(x => x.Id == userId).FirstOrDefault()
            };

            return(View(userViewModel));
        }
        public ActionResult Create(CreateNotificationViewModel viewModel)
        {
            var context = new TrackerDbContext();

            if (ModelState.IsValid)
            {
                viewModel.Notification.StartTime = viewModel.Date;
                viewModel.Notification.StartTime = viewModel.Notification.StartTime.Add(TimeSpan.Parse(viewModel.StartTime.Substring(0, 5)));
                viewModel.Notification.EndTime   = viewModel.Date;
                if (viewModel.EndTime == "00:00")
                {
                    viewModel.Notification.EndTime = viewModel.Notification.EndTime.AddDays(1);
                }
                else
                {
                    viewModel.Notification.EndTime = viewModel.Notification.EndTime.Add(TimeSpan.Parse(viewModel.EndTime.Substring(0, 5)));
                }
                context.Notifications.Add(viewModel.Notification);
                context.SaveChanges();
                return(RedirectToAction("Details", "Issue", new { issueId = viewModel.Notification.IssueId }));
            }
            else
            {
                viewModel.Workers = context.Users.Where(x => x.CompanyId == 1).ToList();
                return(View(viewModel));
            }
        }
        public ActionResult Edit(int notificationId, CreateNotificationViewModel viewModel)
        {
            var context = new TrackerDbContext();

            if (ModelState.IsValid)
            {
                Notification notificationToEdit = context.Notifications.Where(x => x.Id == notificationId).FirstOrDefault();
                notificationToEdit.WorkerId = viewModel.Notification.WorkerId;
                notificationToEdit.WorkDone = viewModel.Notification.WorkDone;

                notificationToEdit.StartTime = viewModel.Date;
                notificationToEdit.StartTime = notificationToEdit.StartTime.Add(TimeSpan.Parse(viewModel.StartTime.Substring(0, 5)));

                notificationToEdit.EndTime = viewModel.Date;
                if (viewModel.EndTime == "00:00")
                {
                    notificationToEdit.EndTime = notificationToEdit.EndTime.AddDays(1);
                }
                else
                {
                    notificationToEdit.EndTime = notificationToEdit.EndTime.Add(TimeSpan.Parse(viewModel.EndTime.Substring(0, 5)));
                }
                context.SaveChanges();
                return(RedirectToAction("Details", "Issue", new { issueId = viewModel.Notification.IssueId }));
            }
            else
            {
                viewModel.Workers = context.Users.Where(x => x.ArchivedTimeStamp == null).Where(x => x.CompanyId == 1).ToList();
                return(View(viewModel));
            }
        }
예제 #6
0
 public ActionResult Create(Company company)
 {
     if (ModelState.IsValid)
     {
         var context = new TrackerDbContext();
         context.Companies.Add(company);
         context.SaveChanges();
         return(RedirectToAction("List"));
     }
     return(View());
 }
예제 #7
0
 public ActionResult Edit(int companyId, Company company)
 {
     if (ModelState.IsValid)
     {
         var     context       = new TrackerDbContext();
         Company companyToEdit = context.Companies.Where(x => x.Id == companyId).FirstOrDefault();
         companyToEdit.Name = company.Name;
         context.SaveChanges();
         return(RedirectToAction("List"));
     }
     return(View());
 }
예제 #8
0
        public ActionResult Delete(User user)
        {
            if (Session["User"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            var  context      = new TrackerDbContext();
            User userToDelete = context.Users.Where(x => x.Id == user.Id).FirstOrDefault();

            userToDelete.Archive();
            context.SaveChanges();
            return(RedirectToAction("List"));
        }
예제 #9
0
        public ActionResult Close(Issue issue)
        {
            if (Session["User"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            var    context      = new TrackerDbContext();
            Status closed       = context.Statuses.Where(x => x.Id == 4).FirstOrDefault();
            Issue  issueToClose = context.Issues.Where(x => x.Id == issue.Id).Include(x => x.Notifications).FirstOrDefault();

            issueToClose.Archive(closed);
            context.SaveChanges();
            return(RedirectToAction("List"));
        }
        public WeightTrackerController(TrackerDbContext context)
        {
            _context = context;

            if (_context.WeightEntries.Count() == 0)
            {
                _context.WeightEntries.Add(new WeightEntryModel {
                    Date   = System.DateTime.Now,
                    Weight = 215.2F,
                    UserId = System.Guid.NewGuid().ToString()
                });
                _context.SaveChanges();
            }
        }
예제 #11
0
        public ActionResult Delete(Company company)
        {
            if (Session["User"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            var context = new TrackerDbContext();

            if (company.Id != 1)
            {
                Company companyToDelete = context.Companies.Where(x => x.Id == company.Id).FirstOrDefault();
                companyToDelete.Archive();
                context.SaveChanges();
            }
            return(RedirectToAction("List"));
        }
예제 #12
0
        public ActionResult Create(User user)
        {
            var context = new TrackerDbContext();

            if (ModelState.IsValid)
            {
                context.Users.Add(user);
                context.SaveChanges();
                return(RedirectToAction("List"));
            }
            CreateUserViewModel userViewModel = new CreateUserViewModel
            {
                Companies = context.Companies.Where(x => x.ArchivedTimeStamp == null).ToList(),
                UserTypes = context.UserTypes.ToList(),
                User      = user
            };

            return(View(userViewModel));
        }
예제 #13
0
        public PomodoroTrackerController(TrackerDbContext context)
        {
            _context = context;

            if (_context.PomodoroEntries.Count() == 0)
            {
                _context.PomodoroEntries.Add(new PomodoroEntryModel {
                    UserId    = System.Guid.NewGuid().ToString(),
                    StartTime = System.DateTime.Now,
                    Modified  = System.DateTime.Now,
                    Planned   = "Sample activity",
                    Actual    = "Sample activity",
                    Elapsed   = 25 * 60,
                    Tags      = "",
                    State     = PomodoroState.NotStarted
                });

                _context.SaveChanges();
            }
        }
예제 #14
0
        public IActionResult Create([FromBody] PomodoroEntryDto model)
        {
            var entry = new PomodoroEntryModel {
                UserId    = model.UserId,
                StartTime = DateTime.Parse(model.StartTime),
                Modified  = DateTime.Now,
                Planned   = model.Planned,
                Actual    = model.Actual,
                Elapsed   = model.Elapsed,
                Tags      = model.Tags,
                State     = (PomodoroState)model.State
            };

            try{
                _context.PomodoroEntries.Add(entry);
                _context.SaveChanges();
                return(CreatedAtRoute("GetPomodoro", new { id = entry.Id }, entry));
            } catch {
                Console.WriteLine("error");
                throw;
            }
        }
예제 #15
0
        public ActionResult Create(Issue issue)
        {
            var context = new TrackerDbContext();

            if (ModelState.IsValid)
            {
                issue.StatusId = 1;
                context.Issues.Add(issue);
                context.SaveChanges();
                return(RedirectToAction("List"));
            }
            else
            {
                CreateIssueViewModel createIssueViewModel = new CreateIssueViewModel()
                {
                    Companies = context.Companies.ToList(),
                    Users     = context.Users.ToList(),
                    Agents    = context.Users.Where(x => x.CompanyId == 1).ToList(),
                    Issue     = issue
                };
                return(View(createIssueViewModel));
            }
        }
예제 #16
0
        public ActionResult Edit(int issueId, Issue issue)
        {
            var context = new TrackerDbContext();

            if (ModelState.IsValid)
            {
                Issue issueToEdit = context.Issues.Where(x => x.Id == issueId).FirstOrDefault();
                issueToEdit.Title      = issue.Title;
                issueToEdit.AgentId    = issue.AgentId;
                issueToEdit.NotifierId = issue.NotifierId;
                issueToEdit.Companyid  = issueToEdit.Companyid;
                context.SaveChanges();
                return(RedirectToAction("List"));
            }
            CreateIssueViewModel issueViewModel = new CreateIssueViewModel()
            {
                Companies = context.Companies.ToList(),
                Users     = context.Users.Where(x => x.ArchivedTimeStamp == null).ToList(),
                Agents    = context.Users.Where(x => x.ArchivedTimeStamp == null).Where(x => x.CompanyId == 1).ToList(),
                Issue     = issue
            };

            return(View(issueViewModel));
        }
예제 #17
0
        public JsonResult Update(string model)
        {
            JavaScriptSerializer serializer  = new JavaScriptSerializer();
            BangTheoDoiToCat     bangtheodoi = serializer.Deserialize <BangTheoDoiToCat>(model);

            //save db...
            var entity = _context.BangTheoDoiToCats.Single(x => x.MaChuyen == bangtheodoi.MaChuyen);

            if (model.Contains("LuyKeThucHien"))
            {
                entity.LuyKeThucHien = bangtheodoi.LuyKeThucHien;
            }
            else if (model.Contains("SLKeHoach"))
            {
                entity.SLKeHoach = bangtheodoi.SLKeHoach;
            }
            else if (model.Contains("ThucHien"))
            {
                entity.ThucHien = bangtheodoi.ThucHien;
            }
            _context.SaveChanges();

            return(Json(new { status = true }, JsonRequestBehavior.AllowGet));
        }
예제 #18
0
 public void Save()
 {
     _trackerDbContext.SaveChanges();
 }
예제 #19
0
        public MovementResult Save(MovementDto movement)
        {
            var result = new MovementResult();

            try
            {
                //check card is valid
                var card =
                    _context.Card.FirstOrDefault(
                        c => string.Equals(c.Uid, movement.Uid, StringComparison.OrdinalIgnoreCase));

                if (card == null)
                {
                    result.IsError      = true;
                    result.ErrorMessage = $"Invalid Card Id: {movement.Uid}";
                    return(result);
                }

                //record movement
                var location = (from d in _context.Device
                                join l in _context.Location on d.LocationId equals l.Id
                                where d.Id.Equals(movement.DeviceId)
                                select l).FirstOrDefault();

                if (location != null)
                {
                    //Check ingress or egress
                    var latestMovement =
                        _context.Movement
                        .OrderByDescending(m => m.SwipeTime)
                        .FirstOrDefault(m => m.CardId == movement.Uid);

                    if (latestMovement == null)
                    {
                        //ingress
                        //first recorded movement
                        result.Ingress = true;
                    }
                    else
                    {
                        //If latest movement this location egress
                        result.Ingress = latestMovement.LocationId != location.Id;
                    }

                    //Location 1 is off site
                    var locationId = result.Ingress ? location.Id : 1;

                    _context.Movement.Add(new Movement
                    {
                        CardId     = movement.Uid,
                        DeviceId   = movement.DeviceId,
                        LocationId = locationId,
                        SwipeTime  = DateTime.Now
                    });

                    _context.SaveChanges();
                }
                else
                {
                    result.IsError      = true;
                    result.ErrorMessage = $"Device location not found deviceId: {movement.DeviceId}";
                    return(result);
                }

                var person = (from c in _context.Card
                              join pc in _context.PersonCard on c.Id equals pc.CardId
                              join p in _context.Person on pc.PersonId equals p.Id
                              where c.Uid.Equals(movement.Uid)
                              select p).FirstOrDefault();

                result.Person = person;
            }
            catch (Exception ex)
            {
                //TODO log
            }

            return(result);
        }