Example #1
0
        public string LoginApi([FromBody] LoginDTO input)
        {
            var username      = input.Username;
            var inputPassword = input.Password.Replace("\n", "");

            var dbUser = _dbContext.Employees.SingleOrDefault(e => e.Username == username);

            if (dbUser != null)
            {
                if (dbUser.Password.Equals(inputPassword))
                {
                    var userRole = dbUser.Role.ToString();
                    var userId   = dbUser.Id;

                    AndroidUser user = new AndroidUser();
                    user.UserId = dbUser.Id;

                    _dbContext.Add(user);
                    _dbContext.SaveChanges();

                    return(JsonSerializer.Serialize(new
                    {
                        response = "Successful",
                        deptRole = userRole
                    }));
                }
            }

            return(JsonSerializer.Serialize(new
            {
                response = "Failed"
            }));
        }
Example #2
0
        // Author: Ayisha
        // Creates a new requisition in the database
        public IActionResult SaveRequisition(DeptRequisition deptRequisition)
        {
            if (getUserRole().Equals(""))
            {
                return(RedirectToAction("Login", "Login"));
            }
            //Security-Emp Lvl
            if (!(getUserRole() == DeptRole.Employee.ToString() ||
                  getUserRole() == DeptRole.DeptRep.ToString() ||
                  getUserRole() == DeptRole.Contact.ToString() ||
                  getUserRole() == DeptRole.DelegatedEmployee.ToString()))
            {
                if (getUserRole() == DeptRole.DeptHead.ToString())
                {
                    return(RedirectToAction(_filterService.Filter(getUserRole()), "Dept"));
                }
                else
                {
                    return(RedirectToAction(_filterService.Filter(getUserRole()), "Store"));
                }
            }
            int      userId = (int)HttpContext.Session.GetInt32("Id");
            Employee user   = _dbContext.Employees.SingleOrDefault(e => e.Id == userId);
            int      deptId = user.Dept.id;

            //get employee from session data
            var    result            = new DeptRequisition();
            string usernameInSession = HttpContext.Session.GetString("username");
            var    employee          = _dbContext.Employees.FirstOrDefault(ep => ep.Username == usernameInSession);

            result.Employee = employee;

            _dbContext.Add(result);

            foreach (var requisitionDetail in deptRequisition.RequisitionDetails)
            {
                requisitionDetail.Stationery =
                    _dbContext.Stationeries.FirstOrDefault(s => s.Id == requisitionDetail.Stationery.Id);
                requisitionDetail.DeptRequisition = result;
                _dbContext.Add(requisitionDetail);
            }

            result.Employee = user;
            _dbContext.SaveChanges();

            return(RedirectToAction("EmployeeRequisitionList", "Dept"));
        }
        public async Task <IActionResult> Create([Bind("OrderDate,Supplier")] PO pO)
        {
            if (getUserRole().Equals(""))
            {
                return(RedirectToAction("Login", "Login"));
            }
            //Security
            if (!(getUserRole() == DeptRole.StoreClerk.ToString() ||
                  getUserRole() == DeptRole.StoreSupervisor.ToString() ||
                  getUserRole() == DeptRole.StoreManager.ToString()))
            {
                return(RedirectToAction(_filterService.Filter(getUserRole()), "Dept"));
            }
            if (ModelState.IsValid)
            {
                var po = new PO();
                po.OrderDate = pO.OrderDate;
                po.POStatus  = po.POStatus;
                po.Supplier  = _context.Suppliers.FirstOrDefault(s => s.Id == pO.Supplier.Id);

                Console.WriteLine(po);
                _context.Add(po);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(pO));
        }
Example #4
0
        // Author: KyawThiha, Yeo Jia Hui
        // Save for New Supplier
        public IActionResult Save(Supplier supplier)
        {
            if (getUserRole().Equals(""))
            {
                return(RedirectToAction("Login", "Login"));
            }
            //Security
            if (!(getUserRole() == DeptRole.StoreClerk.ToString() ||
                  getUserRole() == DeptRole.StoreSupervisor.ToString() ||
                  getUserRole() == DeptRole.StoreManager.ToString()))
            {
                return(RedirectToAction(_filterService.Filter(getUserRole()), "Dept"));
            }
            if (!ModelState.IsValid)
            {
                TempData["error"] = " Supplier, Address, Phone can not be null";
                return(RedirectToAction("CreateNewSupplier"));
            }

            var newSup = new Supplier();

            newSup.Name           = supplier.Name;
            newSup.TelephoneNo    = supplier.TelephoneNo;
            newSup.Address        = supplier.Address;
            newSup.supplierStatus = SupplierStatus.ContractApproved;
            _dbContext.Add(newSup);
            foreach (SupplierDetail sdetail in supplier.SupplierDetails)
            {
                if (sdetail.UnitPrice != 0 || sdetail.UnitPrice > 0)
                {
                    sdetail.Stationery =
                        _dbContext.Stationeries.FirstOrDefault(s => s.Id == sdetail.Stationery.Id);
                    sdetail.Supplier = newSup;
                    _dbContext.Add(sdetail);
                }
            }
            _dbContext.SaveChanges();
            ViewData["username"] = HttpContext.Session.GetString("username");
            return(RedirectToAction("StoreSupplierList"));
        }
Example #5
0
        public void PostSelectedEmp([FromBody] DelagatedEmpFromAndroid input)
        {
            var empName   = input.EmpName;
            var startDate = input.StartDate;
            var endDate   = input.EndDate;

            //string iString = input.OrderDate;
            //newPo.OrderDate = DateTime.ParseExact(iString, "yyyy-MM-dd", null);

            var employee             = _dbContext.Employees.SingleOrDefault(x => x.Name == empName);
            var newDelegatedEmployee = new DelegatedEmployee();

            newDelegatedEmployee.Name     = employee.Name;
            employee.Role                 = DeptRole.DelegatedEmployee;
            newDelegatedEmployee.Employee = employee;
            //newDelegatedEmployee.StartDate = Convert.ToDateTime(startDate);
            //newDelegatedEmployee.EndDate = Convert.ToDateTime(endDate);
            newDelegatedEmployee.StartDate        = DateTime.ParseExact(startDate, "dd-MM-yyyy", null);
            newDelegatedEmployee.EndDate          = DateTime.ParseExact(endDate, "dd-MM-yyyy", null);
            newDelegatedEmployee.delegationStatus = DelegationStatus.Selected;
            SaveEmployeeDelegation(newDelegatedEmployee);
            _dbContext.Add(newDelegatedEmployee);
            _dbContext.SaveChanges();
        }
Example #6
0
        public async Task <IActionResult> Create([Bind("id,DeptCode,DeptName,TelephoneNo,FaxNo,CollectionPoint")] Department department)
        {
            if (getUserRole().Equals(""))
            {
                return(RedirectToAction("Login", "Login"));
            }
            //Security
            if (!(getUserRole() == DeptRole.StoreClerk.ToString() ||
                  getUserRole() == DeptRole.StoreSupervisor.ToString() ||
                  getUserRole() == DeptRole.StoreManager.ToString()))
            {
                return(RedirectToAction(_filterService.Filter(getUserRole()), "Dept"));
            }
            if (ModelState.IsValid)
            {
                _context.Add(department);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["username"] = HttpContext.Session.GetString("username");
            return(View(department));
        }