Exemplo n.º 1
0
        public async Task <IActionResult> Login(LoginViewModel model)
        {
            //Authenticate user
            // call the api to authenticate
            string msg = "";

            try
            {
                var authData = await StaffApi.Authenticate(model);

                if (authData == null || authData.Token == null)
                {
                    ViewBag.Msg = "Incorrect username oor password";
                    return(View(model));
                }
                HttpContext.Session.SetString("JWToken", authData.Token);
                HttpContext.Session.SetString("usrId_", authData.Id.ToString());
            }
            catch (Exception)
            {
                ViewBag.Msg = "An error occured!";
                return(View(model));
            }


            return(Redirect("~/Home/dashboard"));
        }
        public StaffApiControllerTest()
        {
            var config = new MapperConfiguration(cfg => cfg.AddProfile(new Mapper.SKSLayerMapper()));

            _mapper     = new AutoMapper.Mapper(config);
            _mock       = new Mock <IStaffLogic>();
            _controller = new StaffApi(_mock.Object, _mapper, new LoggerFactory().CreateLogger <StaffApi>());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> GetNotesByStaffId(int?id)
        {
            var model = new DashboardViewModel();

            model.NotesForTheSelectedStaff = await StaffApi.GetNotesByStaffId(id.Value);

            return(PartialView("_StaffNotesPartial", model));
        }
Exemplo n.º 4
0
        public async Task <PartialViewResult> SearchStaff(string s)
        {
            s = s.Trim();
            // Process the search string s.
            // if s contains = as in ID=x then search by Id
            // wildcard search involves *
            // mart*  yield all staff with surnames martxxxx
            // * returns all staff

            var model = new DashboardViewModel();

            model.StaffList = new List <StaffListViewModel>();

            if (s == "*")
            {
                model.StaffList = await staffApi.GetAllStaff();
            }
            // searching by surname
            else if (s.Contains("*"))
            {
                // a starting or ending *
                if (s.StartsWith("*"))
                {
                    string surnameSuffix = s.Substring(1);
                    if (!String.IsNullOrEmpty(surnameSuffix))
                    {
                        // search by suffix
                        model.StaffList = await StaffApi.SearchByLastNameSuffix(surnameSuffix);
                    }
                }
                else if (s.EndsWith("*"))
                {
                    string surnamePrefix = s.Substring(0, s.Length - 1);
                    if (!String.IsNullOrEmpty(surnamePrefix))
                    {
                        // search by prefix
                        model.StaffList = await StaffApi.SearchByLastNamePrefix(surnamePrefix);
                    }
                }
            }
            // search by ID
            else if (s.ToLower().Contains("id="))
            {
                string idStr = s.Substring(3);
                int    id    = 0;
                if (int.TryParse(idStr, out id))
                {
                    // search by Id
                    model.StaffList = await StaffApi.SearchStaffById(id);
                }
            }
            // else search by last name
            else
            {
                model.StaffList = await StaffApi.SearchByLastName(s);
            }
            return(PartialView("_StaffList", model));
        }
Exemplo n.º 5
0
 public HomeController(IOptions <AppSettings> appSettings)
 {
     _appSettings = appSettings.Value;
     staffApi     = new StaffApi(_appSettings);
     clientApi    = new ClientsApi(_appSettings);
     exchangeApi  = new ExchangeApi(_appSettings);
     ticketsApi   = new TicketsApi(_appSettings);
     tradesApi    = new TradesApi(_appSettings);
 }
Exemplo n.º 6
0
        public async Task <IActionResult> GetStaffById(int?id)
        {
            if (id == null)
            {
                throw new ArgumentNullException("Invalid request sent!");
            }
            var theStaff = await StaffApi.GetStaffById(id.Value);

            if (theStaff == null)
            {
                return(Json(new { success = false, msg = "record not found!" }));
            }
            return(Json(new { success = true, msg = theStaff }));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> CreateStaffNote(int id, string note)
        {
            if (String.IsNullOrEmpty(note))
            {
                throw new ArgumentNullException("Note cannot be null!");
            }
            try
            {
                await StaffApi.CreateNewNote(id, note);

                return(Json(new { success = true, msg = "Note saved!" }));
            }
            catch (Exception)
            {
                return(Json(new { success = false, msg = "Error creating note!" }));
            }
        }
Exemplo n.º 8
0
        public async Task <IActionResult> SaveOrUpdateStaff(int?id, [FromBody] StaffDTO staff)
        {
            try
            {
                string msg = "";
                if (id == null || id.Value == 0)
                {
                    await StaffApi.CreateNewStaff(staff);

                    msg = "Staff record Added";
                }
                else
                {
                    await StaffApi.UpdateStaff(id.Value, staff);

                    msg = "Staff record Updated";
                }
                return(Json(new { success = true, msg = msg }));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, msg = "Error updating staff records!" }));
            }
        }