public IActionResult Index()
        {
            AspUserService aspUser = new AspUserService(_db, this);

            List <ClassAllocation>      classAllocations    = aspUser.User.List_ClassAllocation.Where(e => e.Deleted == false).OrderByDescending(e => e.DateCreated).ToList();
            MyAttendanceViewModel       model               = new MyAttendanceViewModel();
            List <MyAttendanceViewItem> attendanceViewItems = new List <MyAttendanceViewItem>();

            foreach (ClassAllocation item in classAllocations)
            {
                List <Attendance>     classAttendances    = item.Class.List_Attendances.Where(e => e.Deleted == false).ToList();
                List <AttendanceItem> studentAttendances  = item.Student.List_AttendanceItems.Where(e => classAttendances.Contains(e.Attendance)).ToList();
                MyAttendanceViewItem  newMyAttendanceItem = new MyAttendanceViewItem()
                {
                    ClassName  = item.Class.Name,
                    Attendance = studentAttendances.Count().ToString() + "/" + classAttendances.Count().ToString(),
                    DateJoined = item.DateCreated
                };

                attendanceViewItems.Add(newMyAttendanceItem);
            }

            model.StudentName = aspUser.User.Name;
            model.Classes     = attendanceViewItems;
            return(View(model));
        }
Ejemplo n.º 2
0
        public StudentInfoOutput AddToClass([FromBody] StudentInfoInput input)
        {
            StudentInfoOutput output = new StudentInfoOutput();

            if (input == null)
            {
                Response.StatusCode = 400;
                output.Result       = "INPUT_IS_NULL";
            }
            else
            {
                Class thisClass = _db.Classes.Where(e => e.ClassCode.ToUpper().Equals(input.ClassCode.ToUpper()) && e.Deleted == false).FirstOrDefault();
                if (thisClass == null)
                {
                    Response.StatusCode = 400;
                    output.Result       = "CLASS_NOT_EXIST";
                }
                else
                {
                    AspUserService aspUser = new AspUserService(_db, this);
                    if (aspUser.IsAdmin)
                    {
                        BCPUser student = _db._BCPUsers.Where(e => e.Id.Equals(input.StudentId) && e.Deleted == false).FirstOrDefault();
                        if (student == null)
                        {
                            Response.StatusCode = 400;
                            output.Result       = "STUDENT_NOT_EXIST";
                        }
                        else
                        {
                            ClassAllocation ca = _db.ClassAllocations.Where(e => e.Class == thisClass && e.Student == student && e.Deleted == false).FirstOrDefault();
                            if (ca == null)
                            {
                                ClassAllocation newCa = new ClassAllocation()
                                {
                                    Class   = thisClass,
                                    Student = student
                                };

                                _db.ClassAllocations.Add(newCa);
                                _db.SaveChanges();
                                output.Result = "OK";
                            }
                            else
                            {
                                Response.StatusCode = 400;
                                output.Result       = "ALREAD_ADDED";
                            }
                        }
                    }
                    else
                    {
                        Response.StatusCode = 400;
                        output.Result       = "NO_PRIVILEGE";
                    }
                }
            }

            return(output);
        }
Ejemplo n.º 3
0
        public IActionResult AddFace(string id)
        {
            AspUserService aspUser = new AspUserService(_db, this);

            if (aspUser.IsAdmin)
            {
                BCPUser student = _db._BCPUsers.Where(e => e.Id.Equals(id)).FirstOrDefault();

                if (student == null)
                {
                    return(RedirectToAction("Index", "Student"));
                }
                else
                {
                    List <Recognizer> recognizers  = _db.Recognizers.Where(e => e.Deleted == false).OrderBy(e => e.Id).ToList();
                    StudentViewModel  studentModel = new StudentViewModel();
                    AddFaceViewModel  model        = new AddFaceViewModel();

                    studentModel.StudentName   = student.Name;
                    studentModel.AccountRole   = student.Status;
                    studentModel.StudentImages = student.List_UserImage.Where(e => e.Deleted == false && e.Status == 2).OrderByDescending(e => e.Confidence).ToList();
                    studentModel.StudentId     = id;

                    ViewBag.SiteUrl   = _db.SiteConfigs.Where(e => e.Key.Equals("SITEURL")).First().Value;
                    model.Student     = studentModel;
                    model.Recognizers = recognizers;

                    return(View(model));
                }
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Ejemplo n.º 4
0
        public ClassInfoOutput Remove([FromBody] ClassInfoInput input)
        {
            ClassInfoOutput output  = new ClassInfoOutput();
            AspUserService  aspUser = new AspUserService(_db, this);

            if (input == null)
            {
                Response.StatusCode = 400;
                output.Result       = "INPUT_IS_NULL";
            }
            else
            {
                if (aspUser.IsAdmin)
                {
                    Class selectedClass = _db.Classes.Where(e => e.Id.Equals(input.ClassId)).FirstOrDefault();
                    selectedClass.Deleted = true;
                    output.Result         = "OK";
                    _db.SaveChanges();
                }
                else
                {
                    Response.StatusCode = 400;
                    output.Result       = "NO_PRIVILEGE";
                }
            }

            return(output);
        }
Ejemplo n.º 5
0
        public IActionResult Index(string id)
        {
            ViewBag.Nav = 3;
            if (string.IsNullOrEmpty(id))
            {
                return(RedirectToAction("Index", "Order"));
            }
            else
            {
                AspUserService aspUser = new AspUserService(_db, this);
                Order          order   = _db.Orders.Where(e => e.Id.Equals(id) && e.Deleted == false).FirstOrDefault();

                if (order.Vendor.Owner == aspUser.User || aspUser.IsStaff)
                {
                    OrderItemListViewModel model = new OrderItemListViewModel();

                    model.SelectedVendor = order.Vendor;
                    model.Order          = order;
                    if (order.OrderItems != null)
                    {
                        model.OrderItems = order.OrderItems.OrderByDescending(e => e.DateCreated).ToList();
                    }

                    return(View(model));
                }
                else
                {
                    return(RedirectToAction("Index", "Order"));
                }
            }
        }
Ejemplo n.º 6
0
        public MenuItemInfoOutput RemoveMenuItem([FromBody] MenuItemInfoInput input)
        {
            MenuItemInfoOutput output = new MenuItemInfoOutput();

            if (!string.IsNullOrEmpty(input.MenuItemId))
            {
                MenuItem       menuItem    = _db.MenuItems.Where(e => e.Id.Equals(input.MenuItemId)).FirstOrDefault();
                AspUserService userService = new AspUserService(_db, this);

                if (menuItem == null)
                {
                    output.Result = "DOES_NOT_EXIST";
                }
                else
                {
                    if (userService.IsStaff || menuItem.Menu.Vendor.Owner == userService.User)
                    {
                        menuItem.Deleted = true;
                        _db.SaveChanges();
                        output.Result = "OK";
                    }
                    else
                    {
                        output.Result = "NO_PRIVILEGE";
                    }
                }
            }
            else
            {
                output.Result = "INPUT_IS_NULL";
            }

            return(output);
        }
Ejemplo n.º 7
0
        public IActionResult Detail(string id)
        {
            ViewBag.Nav = 4;
            if (string.IsNullOrEmpty(id))
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                AspUserService aspUser = new AspUserService(_db, this);

                if (aspUser.IsValid)
                {
                    MyOrderDetailViewModel model      = new MyOrderDetailViewModel();
                    List <OrderItem>       orderItems = new List <OrderItem>();

                    Order order = aspUser.User.ListOrders.Where(e => e.Deleted == false && e.Id.Equals(id)).FirstOrDefault();
                    foreach (OrderItem item in order.OrderItems.Where(e => e.Deleted == false))
                    {
                        orderItems.Add(item);
                    }

                    model.OrderId    = order.Id;
                    model.OrderItems = orderItems;
                    return(View(model));
                }
                else
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
        }
Ejemplo n.º 8
0
        public MenuInfoOutput DeleteMenu([FromBody] MenuInfoInput input)
        {
            Menu           menu    = _db.Menus.Where(e => e.Id.Equals(input.MenuId) && e.Deleted == false).FirstOrDefault();
            AspUserService aspUser = new AspUserService(_db, this);
            MenuInfoOutput output  = new MenuInfoOutput();

            if (menu == null)
            {
                output.Result = "DOES_NOT_EXIST";
            }
            else
            {
                if (menu.Vendor.Owner == aspUser.User || aspUser.IsStaff)
                {
                    menu.Deleted = true;
                    _db.SaveChanges();
                    output.Result = "OK";
                }
                else
                {
                    output.Result = "NO_PRIVILEGE";
                }
            }

            return(output);
        }
Ejemplo n.º 9
0
 public ActionResult Login(AspUserLoginForm form)
 {
     try
     {
         ViewBag.Success = true;
         ViewBag.Message = "Success";
         if (!ModelState.IsValid)
         {
             throw new Exception();
         }
         AspUserService service = new AspUserService();
         int?           id      = service.CheckPassword(form.Mail, form.Password);
         if (id is null)
         {
             throw new Exception();
         }
         AspUser user = service.Get((int)id);
         Utils.SessionUser = user;
         return(RedirectToAction("Index"));
     }
     catch (Exception)
     {
         ViewBag.Success = false;
         ViewBag.Message = "Failed";
         return(View(form));
     }
 }
Ejemplo n.º 10
0
        public IActionResult Index(string id)
        {
            ViewBag.Nav = 2;
            MenuItemListViewModel model = new MenuItemListViewModel();

            model.Menu = _db.Menus.Where(e => e.Id.Equals(id) && e.Deleted == false).FirstOrDefault();
            AspUserService userService = new AspUserService(_db, this);

            if (model.Menu == null)
            {
                return(RedirectToAction("Index", "Menu"));
            }
            else
            {
                if (userService.User == model.Menu.Vendor.Owner || userService.IsStaff)
                {
                    model.MenuItems = model.Menu.MenuItems.Where(e => e.Deleted == false).OrderByDescending(e => e.Name).ToList();
                    model.Vendor    = model.Menu.Vendor;
                    return(View(model));
                }
                else
                {
                    return(RedirectToAction("Index", "Menu"));
                }
            }
        }
Ejemplo n.º 11
0
        public VendorInfoOutput DeleteById([FromBody] VendorInfoInput input)
        {
            VendorInfoOutput output  = new VendorInfoOutput();
            AspUserService   aspUser = new AspUserService(_db, this);

            if (!aspUser.IsStaff)
            {
                output.Result = "NO_PRIVILEGE";
            }
            else
            {
                Vendor vendor = _db.Vendors.Where(e => e.Id.Equals(input.Id) && e.Deleted == false).FirstOrDefault();
                if (vendor == null)
                {
                    output.Result = "NOT_FOUND";
                }
                else
                {
                    vendor.Deleted   = true;
                    vendor.DeletedBy = _db._Users.Where(e => e.AspNetUser.Id.Equals(User.FindFirstValue(ClaimTypes.NameIdentifier))).FirstOrDefault().Id;
                    _db.SaveChanges();
                    output.Result = "OK";
                }
            }

            return(output);
        }
Ejemplo n.º 12
0
        public VendorCheckUserOutput CheckUser([FromBody] VendorCheckUserInput input)
        {
            VendorCheckUserOutput output  = new VendorCheckUserOutput();
            AspUserService        aspUser = new AspUserService(_db, this);

            if (!aspUser.IsStaff)
            {
                output.Result = "NO_PRIVILEGE";
            }
            else
            {
                User user = _db._Users.Where(e => e.Email.ToLower().Equals(input.Email) && e.Deleted == false).FirstOrDefault();
                if (user == null)
                {
                    output.Result = "USER_NOT_FOUND";
                }
                else
                {
                    output.FirstName = user.FName;
                    output.LastName  = user.LName;
                    output.UserID    = user.Id;
                    output.Result    = "OK";
                }
            }
            return(output);
        }
Ejemplo n.º 13
0
        public ClassInfoOutput CheckClassById([FromBody] ClassInfoInput input)
        {
            ClassInfoOutput output  = new ClassInfoOutput();
            AspUserService  aspUser = new AspUserService(_db, this);

            if (input == null)
            {
                Response.StatusCode = 400;
                output.Result       = "INPUT_IS_NULL";
            }
            else
            {
                if (aspUser.IsAdmin)
                {
                    Class selectedClass = _db.Classes.Where(e => e.Id.Equals(input.ClassId)).FirstOrDefault();
                    if (selectedClass == null)
                    {
                        Response.StatusCode = 400;
                        output.Result       = "CLASS_NOT_EXIST";
                    }
                    else
                    {
                        output.ClassName = selectedClass.Name;
                        output.Result    = "OK";
                    }
                }
                else
                {
                    Response.StatusCode = 400;
                    output.Result       = "NO_PRIVILEGE";
                }
            }

            return(output);
        }
Ejemplo n.º 14
0
        public IActionResult TakeAttendance(string id)
        {
            if (User.IsInRole("LECTURER"))
            {
                AspUserService aspUser = new AspUserService(_db, this);
                if (aspUser.IsLecturer)
                {
                    Class thisClass = aspUser.User.List_Classes.Where(e => e.Id.Equals(id) && e.Deleted == false).FirstOrDefault();
                    if (thisClass == null)
                    {
                        return(RedirectToAction("Index", "MyClass"));
                    }
                    else
                    {
                        MyClassAttendanceViewModel model = new MyClassAttendanceViewModel()
                        {
                            ClassId     = thisClass.Id,
                            ClassName   = thisClass.Name,
                            Recognizers = _db.Recognizers.Where(e => e.Deleted == false).ToList()
                        };

                        return(View(model));
                    }
                }
                else
                {
                    return(RedirectToAction("Index", "MyClass"));
                }
            }
            else
            {
                return(RedirectToAction("Index", "MyClass"));
            }
        }
Ejemplo n.º 15
0
        public CreateMenuOutput CreateMenu([FromBody] CreateMenuInput input)
        {
            Vendor           vendor  = _db.Vendors.Where(e => e.Id.Equals(input.VendorId) && e.Deleted == false).FirstOrDefault();
            AspUserService   aspUser = new AspUserService(_db, this);
            CreateMenuOutput output  = new CreateMenuOutput();

            if (vendor == null)
            {
                output.Result = "DOES_NOT_EXIST";
            }
            else
            {
                if (vendor.Owner == aspUser.User || aspUser.IsStaff)
                {
                    Menu newMenu = new Menu()
                    {
                        Name = input.MenuName
                    };

                    vendor.Menus.Add(newMenu);
                    _db.SaveChanges();
                    output.Result = "OK";
                }
                else
                {
                    output.Result = "NO_PRIVILEGE";
                }
            }

            return(output);
        }
Ejemplo n.º 16
0
        public UserInfoOutput CheckUserById([FromBody] UserInfoInput input)
        {
            UserInfoOutput output  = new UserInfoOutput();
            AspUserService aspUser = new AspUserService(_db, this);

            if (aspUser.IsAdmin)
            {
                if (input == null)
                {
                    Response.StatusCode = 400;
                    output.Result       = "INPUT_IS_NULL";
                }
                else
                {
                    BCPUser user = _db._BCPUsers.Where(e => e.Id.Equals(input.UserId)).FirstOrDefault();
                    if (user == null)
                    {
                        Response.StatusCode = 400;
                        output.Result       = "USER_NOT_EXIST";
                    }
                    else
                    {
                        output.Email  = user.Email;
                        output.Name   = user.Name;
                        output.Result = "OK";
                    }
                }
            }
            else
            {
                Response.StatusCode = 400;
                output.Result       = "NO_PRIVILEGE";
            }
            return(output);
        }
Ejemplo n.º 17
0
        public async Task <UserInfoOutput> CheckRole()
        {
            UserInfoOutput output  = new UserInfoOutput();
            AspUserService aspUser = new AspUserService(_db, this);

            if (aspUser.User.Status == 1)
            {
                if (User.IsInRole("LECTURER"))
                {
                    await _userManager.RemoveFromRoleAsync(aspUser.User.AspUser, "LECTURER");
                }
                if (User.IsInRole("ADMIN"))
                {
                    await _userManager.RemoveFromRoleAsync(aspUser.User.AspUser, "ADMIN");
                }
            }

            if (aspUser.User.Status == 2)
            {
                if (!User.IsInRole("LECTURER"))
                {
                    await _userManager.AddToRoleAsync(aspUser.User.AspUser, "LECTURER");
                }
                if (User.IsInRole("ADMIN"))
                {
                    await _userManager.RemoveFromRoleAsync(aspUser.User.AspUser, "ADMIN");
                }
            }

            if (aspUser.User.Status == 3)
            {
                if (User.IsInRole("LECTURER"))
                {
                    await _userManager.RemoveFromRoleAsync(aspUser.User.AspUser, "LECTURER");
                }
                if (!User.IsInRole("ADMIN"))
                {
                    await _userManager.AddToRoleAsync(aspUser.User.AspUser, "ADMIN");
                }
            }

            if (aspUser.User.Status == 4)
            {
                if (!User.IsInRole("LECTURER"))
                {
                    await _userManager.AddToRoleAsync(aspUser.User.AspUser, "LECTURER");
                }
                if (!User.IsInRole("ADMIN"))
                {
                    await _userManager.AddToRoleAsync(aspUser.User.AspUser, "ADMIN");
                }
            }

            await _signInManager.SignOutAsync();

            await _signInManager.SignInAsync(aspUser.User.AspUser, true);

            output.Result = "OK";
            return(output);
        }
        public RecognizerTaskOutput GroupImageCapture([FromBody] RecognizerTaskInput input)
        {
            RecognizerTaskOutput output = new RecognizerTaskOutput();

            if (input == null)
            {
                Response.StatusCode = 400;
                output.Result       = "INPUT_IS_NULL";
            }
            else
            {
                AspUserService aspUser = new AspUserService(_db, this);
                if (aspUser.IsAdmin)
                {
                    Recognizer recognizer = _db.Recognizers.Where(e => e.Id.Equals(input.RecognizerId) && e.Deleted == false).FirstOrDefault();
                    Class      thisClass  = aspUser.User.List_Classes.Where(e => e.Id.Equals(input.ClassId) && e.Deleted == false).FirstOrDefault();

                    if (recognizer == null)
                    {
                        Response.StatusCode = 400;
                        output.Result       = "RECOGNIZER_NOT_FOUND";
                    }
                    else if (thisClass == null)
                    {
                        Response.StatusCode = 400;
                        output.Result       = "CLASS_NOT_FOUND";
                    }
                    else
                    {
                        List <GroupImage> groupImages = thisClass.List_GroupImages.Where(e => e.Deleted == false && e.Status != 0).ToList();
                        foreach (GroupImage item in groupImages)
                        {
                            item.Status = 0;
                        }

                        RecognizerTask task = new RecognizerTask()
                        {
                            Command        = "CAPTURE_CLASS_IMAGE",
                            Status         = 1,
                            Recognizer     = recognizer,
                            PrimaryValue   = thisClass.Id,
                            SecondaryValue = (int.Parse(_db.SiteConfigs.Where(e => e.Key.Equals("NUM_PHOTO_PER_CLASS")).FirstOrDefault().Value) + 5).ToString()
                        };

                        _db.RecognizerTasks.Add(task);
                        _db.SaveChanges();

                        output.RecognizerTaskId = task.Id;
                        output.Result           = "OK";
                    }
                }
                else
                {
                    Response.StatusCode = 400;
                    output.Result       = "NO_PRIVILEGE";
                }
            }

            return(output);
        }
        public RecognizerTaskOutput StudentImageCapture([FromBody] RecognizerTaskInput input)
        {
            RecognizerTaskOutput output = new RecognizerTaskOutput();

            if (input == null)
            {
                Response.StatusCode = 400;
                output.Result       = "INPUT_IS_NULL";
            }
            else
            {
                AspUserService aspUser = new AspUserService(_db, this);
                if (aspUser.IsAdmin)
                {
                    Recognizer recognizer = _db.Recognizers.Where(e => e.Id.Equals(input.RecognizerId) && e.Deleted == false).FirstOrDefault();
                    BCPUser    student    = _db._BCPUsers.Where(e => e.Id.Equals(input.StudentId) && e.Deleted == false).FirstOrDefault();

                    if (recognizer == null)
                    {
                        Response.StatusCode = 400;
                        output.Result       = "RECOGNIZER_NOT_FOUND";
                    }
                    else if (student == null)
                    {
                        Response.StatusCode = 400;
                        output.Result       = "STUDENT_NOT_FOUND";
                    }
                    else
                    {
                        List <UserImage> studentImages = student.List_UserImage.Where(e => e.Deleted == false && e.Status != 0).ToList();
                        foreach (UserImage item in studentImages)
                        {
                            item.Status = 0;
                        }

                        RecognizerTask task = new RecognizerTask()
                        {
                            Command        = "REGISTER_NEW_FACE",
                            Status         = 1,
                            Recognizer     = recognizer,
                            PrimaryValue   = student.Id,
                            SecondaryValue = (int.Parse(_db.SiteConfigs.Where(e => e.Key.Equals("NUM_PHOTO_PER_STUDENT")).FirstOrDefault().Value) + 5).ToString()
                        };

                        _db.RecognizerTasks.Add(task);
                        _db.SaveChanges();

                        output.RecognizerTaskId = task.Id;
                        output.Result           = "OK";
                    }
                }
                else
                {
                    Response.StatusCode = 400;
                    output.Result       = "NO_PRIVILEGE";
                }
            }

            return(output);
        }
Ejemplo n.º 20
0
        public ClassInfoOutput Change([FromBody] ClassInfoInput input)
        {
            ClassInfoOutput output = new ClassInfoOutput();

            if (input == null)
            {
                Response.StatusCode = 400;
                output.Result       = "INPUT_IS_NULL";
            }
            else
            {
                AspUserService aspUser = new AspUserService(_db, this);
                if (aspUser.IsAdmin)
                {
                    Class thisClass = _db.Classes.Where(e => e.Id.Equals(input.ClassId) && e.Deleted == false).FirstOrDefault();
                    if (thisClass == null)
                    {
                        Response.StatusCode = 400;
                        output.Result       = "CLASS_NOT_EXIST";
                    }
                    else
                    {
                        BCPUser lecturer = _db._BCPUsers.Where(e => e.Id.Equals(input.LecturerId) && e.Deleted == false).Where(e => e.Status == 2 || e.Status == 4).FirstOrDefault();
                        if (lecturer == null && !string.IsNullOrEmpty(input.LecturerId))
                        {
                            Response.StatusCode = 400;
                            output.Result       = "LECTURER_NOT_EXIST";
                        }
                        else
                        {
                            thisClass.Capacity = input.Capacity;
                            thisClass.Name     = input.ClassName;
                            if (string.IsNullOrEmpty(input.LecturerId))
                            {
                                thisClass.Lecturer = null;
                            }
                            else
                            {
                                thisClass.Lecturer = lecturer;
                            }

                            _db.SaveChanges();
                            output.Result = "OK";
                        }
                    }
                }
                else
                {
                    Response.StatusCode = 400;
                    output.Result       = "NO_PRIVILEGE";
                }
            }

            return(output);
        }
Ejemplo n.º 21
0
        public IActionResult Detail(string id)
        {
            if (User.IsInRole("LECTURER"))
            {
                AspUserService aspUser = new AspUserService(_db, this);
                if (aspUser.IsLecturer)
                {
                    Class thisClass = aspUser.User.List_Classes.Where(e => e.Id.Equals(id) && e.Deleted == false).FirstOrDefault();
                    if (thisClass == null)
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        List <Attendance>        classAttendances = thisClass.List_Attendances.Where(e => e.Deleted == false).ToList();
                        List <ClassAllocation>   classAllocations = thisClass.List_ClassAllocation.Where(e => e.Deleted == false).ToList();
                        List <MyClassDetailItem> classDetails     = new List <MyClassDetailItem>();

                        foreach (ClassAllocation item in classAllocations)
                        {
                            List <AttendanceItem> studentAttendances = item.Student.List_AttendanceItems.Where(e => classAttendances.Contains(e.Attendance)).ToList();
                            MyClassDetailItem     newClassDetail     = new MyClassDetailItem()
                            {
                                StudentId       = item.Student.Id,
                                StudentName     = item.Student.Name,
                                DateJoined      = item.DateCreated,
                                AttendanceCount = studentAttendances.Count().ToString() + "/" + classAttendances.Count().ToString()
                            };

                            classDetails.Add(newClassDetail);
                        }

                        MyClassDetailViewModel model = new MyClassDetailViewModel()
                        {
                            ClassName     = thisClass.Name,
                            ClassId       = thisClass.Id,
                            Students      = classDetails,
                            ClassCapacity = thisClass.Capacity.ToString(),
                            ClassCode     = thisClass.ClassCode.ToUpper(),
                            LecturerName  = thisClass.Lecturer.Name
                        };

                        return(View(model));
                    }
                }
                else
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Ejemplo n.º 22
0
        public ClassInfoOutput AddPhoto([FromBody] ClassInfoInput input)
        {
            ClassInfoOutput output = new ClassInfoOutput();

            if (input == null)
            {
                Response.StatusCode = 400;
                output.Result       = "INPUT_IS_NULL";
            }
            else
            {
                AspUserService aspUser    = new AspUserService(_db, this);
                Recognizer     recognizer = _db.Recognizers.Where(e => e.Id.Equals(input.RecognizerId) && e.Deleted == false).FirstOrDefault();
                if (recognizer == null)
                {
                    Response.StatusCode = 400;
                    output.Result       = "RECOGNIZER_NOT_EXIST";
                }
                else
                {
                    if (recognizer.Key.Equals(input.RecognizerKey))
                    {
                        Class thisClass = _db.Classes.Where(e => e.Id.Equals(input.ClassId) && e.Deleted == false).FirstOrDefault();
                        if (thisClass == null)
                        {
                            Response.StatusCode = 400;
                            output.Result       = "CLASS_NOT_EXIST";
                        }
                        else
                        {
                            GroupImage gi = new GroupImage
                            {
                                Url       = input.ImageUrl,
                                Class     = thisClass,
                                CreatedBy = recognizer.Id,
                                Status    = 1
                            };

                            _db.GroupImages.Add(gi);
                            _db.SaveChanges();
                            output.Result = "OK";
                        }
                    }
                    else
                    {
                        Response.StatusCode = 400;
                        output.Result       = "CREDENTIAL_ERROR";
                    }
                }
            }

            return(output);
        }
Ejemplo n.º 23
0
        public ClassInfoOutput Create([FromBody] ClassInfoInput input)
        {
            ClassInfoOutput output  = new ClassInfoOutput();
            AspUserService  aspUser = new AspUserService(_db, this);

            if (aspUser.IsAdmin)
            {
                if (input == null)
                {
                    Response.StatusCode = 400;
                    output.Result       = "INPUT_IS_NULL";
                }
                else
                {
                    if (string.IsNullOrEmpty(input.ClassName) || string.IsNullOrEmpty(input.ClassCode))
                    {
                        Response.StatusCode = 400;
                        output.Result       = "INPUT_IS_NULL";
                    }
                    else
                    {
                        Class thisClass = _db.Classes.Where(e => e.ClassCode.ToUpper().Equals(input.ClassCode.ToUpper()) && e.Deleted == false).FirstOrDefault();

                        if (thisClass == null)
                        {
                            Class newClass = new Class()
                            {
                                Name      = input.ClassName,
                                ClassCode = input.ClassCode.ToUpper(),
                                CreatedBy = aspUser.User.Id
                            };

                            output.Result = "OK";

                            _db.Classes.Add(newClass);
                            _db.SaveChanges();
                        }
                        else
                        {
                            Response.StatusCode = 400;
                            output.Result       = "CLASS_EXIST";
                        }
                    }
                }
            }
            else
            {
                Response.StatusCode = 400;
                output.Result       = "NO_PRIVILEGE";
            }

            return(output);
        }
Ejemplo n.º 24
0
        public StudentPendingPhotoOutput RetrievePendingPhoto([FromBody] StudentPendingPhotoInput input)
        {
            StudentPendingPhotoOutput output = new StudentPendingPhotoOutput();

            if (input == null)
            {
                Response.StatusCode = 400;
                output.Result       = "INPUT_IS_NULL";
            }
            else
            {
                AspUserService aspUser = new AspUserService(_db, this);
                if (aspUser.IsAdmin)
                {
                    BCPUser student = _db._BCPUsers.Where(e => e.Id.Equals(input.StudentId)).FirstOrDefault();

                    if (student == null)
                    {
                        Response.StatusCode = 400;
                        output.Result       = "STUDENT_NOT_EXIST";
                    }
                    else
                    {
                        List <UserImage>        images     = student.List_UserImage.Where(e => e.Deleted == false && e.Status == 1).OrderByDescending(e => e.Confidence).ToList();
                        List <PendingPhotoItem> photoItems = new List <PendingPhotoItem>();
                        string siteUrl = _db.SiteConfigs.Where(e => e.Key.Equals("SITEURL")).First().Value;

                        foreach (UserImage item in images)
                        {
                            PendingPhotoItem newPhotoItem = new PendingPhotoItem()
                            {
                                UserImageId = item.Id,
                                Url         = siteUrl + "/" + item.Url,
                                DateAdded   = item.DateCreated
                            };

                            photoItems.Add(newPhotoItem);
                        }

                        output.Photos = photoItems;
                        output.Result = "OK";
                    }
                }
                else
                {
                    Response.StatusCode = 400;
                    output.Result       = "NO_PRIVILEGE";
                }
            }

            return(output);
        }
Ejemplo n.º 25
0
        public IActionResult Edit(string id)
        {
            ViewBag.Nav = 3;
            OrderListViewModel model      = new OrderListViewModel();
            AspUserService     aspUser    = new AspUserService(_db, this);
            List <Vendor>      vendorList = aspUser.User.ListVendors.Where(e => e.Deleted == false).OrderBy(e => e.Name).ToList();

            model.VendorList     = vendorList;
            model.SelectedVendor = vendorList.Where(e => e.Id.Equals(id)).FirstOrDefault();
            model.OrderList      = model.SelectedVendor.Orders.Where(e => e.Deleted == false).OrderByDescending(e => e.DateCreated).ToList();

            return(View(model));
        }
Ejemplo n.º 26
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            AspUserService _service = new AspUserService();

            if (Utils.SessionUser is null)
            {
                return(false);
            }
            if (_service.HaveDefaultRight(Utils.SessionUser.Id))
            {
                return(true);
            }
            return(false);
        }
        public RecognizerTaskOutput CheckStatusById([FromBody] RecognizerTaskInput input)
        {
            RecognizerTaskOutput output = new RecognizerTaskOutput();

            if (input == null)
            {
                Response.StatusCode = 400;
                output.Result       = "INPUT_IS_NULL";
            }
            else
            {
                AspUserService aspUser = new AspUserService(_db, this);
                if (aspUser.IsAdmin)
                {
                    RecognizerTask task = _db.RecognizerTasks.Where(e => e.Id.Equals(input.RecognizerTaskId) && e.Deleted == false).FirstOrDefault();
                    if (task == null)
                    {
                        Response.StatusCode = 400;
                        output.Result       = "TASK_NOT_EXIST";
                    }
                    else
                    {
                        if (task.Status == 0)
                        {
                            output.Status = "CANCELLED";
                        }
                        else if (task.Status == 1)
                        {
                            output.Status = "UNREAD";
                        }
                        else if (task.Status == 2)
                        {
                            output.Status = "READ";
                        }
                        else if (task.Status == 3)
                        {
                            output.Status = "DONE";
                        }
                        output.Result = "OK";
                    }
                }
                else
                {
                    Response.StatusCode = 400;
                    output.Result       = "NO_PRIVILEGE";
                }
            }

            return(output);
        }
Ejemplo n.º 28
0
        public ClassInfoOutput RemoveStudent([FromBody] ClassInfoInput input)
        {
            ClassInfoOutput output = new ClassInfoOutput();

            if (input == null)
            {
                Response.StatusCode = 400;
                output.Result       = "INPUT_IS_NULL";
            }
            else
            {
                AspUserService aspUser = new AspUserService(_db, this);
                if (aspUser.IsAdmin)
                {
                    Class thisClass = _db.Classes.Where(e => e.Id.Equals(input.ClassId) && e.Deleted == false).FirstOrDefault();
                    if (thisClass == null)
                    {
                        Response.StatusCode = 400;
                        output.Result       = "CLASS_NOT_EXIST";
                    }
                    else
                    {
                        List <ClassAllocation> classAllocationList = thisClass.List_ClassAllocation.Where(e => e.Student.Id.Equals(input.StudentId) && e.Deleted == false).ToList();
                        if (classAllocationList.Count() > 0)
                        {
                            foreach (ClassAllocation item in classAllocationList)
                            {
                                item.Deleted = true;
                            }

                            _db.SaveChanges();
                            output.Result = "OK";
                        }
                        else
                        {
                            Response.StatusCode = 400;
                            output.Result       = "STUDENT_NOT_IN_CLASS";
                        }
                    }
                }
                else
                {
                    Response.StatusCode = 400;
                    output.Result       = "NO_PRIVILEGE";
                }
            }

            return(output);
        }
Ejemplo n.º 29
0
        public IActionResult Index()
        {
            AspUserService aspUser    = new AspUserService(_db, this);
            List <Vendor>  vendorList = aspUser.User.ListVendors.Where(e => e.Deleted == false).OrderBy(e => e.Name).ToList();

            if (vendorList.Count == 0)
            {
                ViewBag.Nav = 3;
                return(View());
            }
            else
            {
                return(RedirectToAction("Edit", "Order", new { id = vendorList.First().Id }));
            }
        }
Ejemplo n.º 30
0
        public ClassPendingPhotoOutput RetrievePendingPhoto([FromBody] ClassPendingPhotoInput input)
        {
            ClassPendingPhotoOutput output = new ClassPendingPhotoOutput();

            if (input == null)
            {
                Response.StatusCode = 400;
                output.Result       = "INPUT_IS_NULL";
            }
            else
            {
                AspUserService aspUser = new AspUserService(_db, this);
                if (aspUser.IsLecturer)
                {
                    Class thisClass = aspUser.User.List_Classes.Where(e => e.Id.Equals(input.ClassId) && e.Deleted == false).FirstOrDefault();
                    if (thisClass == null)
                    {
                        Response.StatusCode = 400;
                        output.Result       = "CLASS_NOT_EXIST";
                    }
                    else
                    {
                        string                       siteUrl = _db.SiteConfigs.Where(e => e.Key.Equals("SITEURL")).FirstOrDefault().Value;
                        List <GroupImage>            images  = thisClass.List_GroupImages.Where(e => e.Status == 1 && e.Deleted == false).ToList();
                        List <ClassPendingPhotoItem> photos  = new List <ClassPendingPhotoItem>();
                        foreach (GroupImage item in images)
                        {
                            ClassPendingPhotoItem photoItem = new ClassPendingPhotoItem()
                            {
                                Url = siteUrl + "/" + item.Url
                            };
                            photos.Add(photoItem);
                        }

                        output.Photos = photos;
                        output.Result = "OK";
                    }
                }
                else
                {
                    Response.StatusCode = 400;
                    output.Result       = "NO_PRIVILEGE";
                }
            }

            return(output);
        }