Exemplo n.º 1
0
 // POST api/<controller> - update card
 public ResponseObject Post([FromBody]CardDto card)
 {
     if (card == null)
         throw new ArgumentException("Wrong parameter");
     var currentUser = new UserService().FindByName(User.Identity.Name);
     var id = new CardService().Save(card.ID, card.Word, card.Translation, currentUser);
     return ResponseObject.Success(id);
 }
Exemplo n.º 2
0
 // GET api/<controller> - return list of cards
 public ResponseObject Get()
 {
     var currentUser = new UserService().FindByName(User.Identity.Name);
     var cardService = new CardService();
     var list = cardService.List(currentUser.Id);
     List<CardDto> result = list.ConvertAll(c => new CardDto(c));
     return ResponseObject.Success(result);
 }
Exemplo n.º 3
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var sessionCookie = filterContext.HttpContext.Request.Cookies.Get("SuperMemoSession");

            var userService = new UserService();
            if (sessionCookie == null || userService.FindByHash(sessionCookie.Value) == null)
            {
                filterContext.Result = new RedirectToRouteResult(
                    new RouteValueDictionary {{"controller", "Authorization"}, {"action", "Login"}});
            }
        }
Exemplo n.º 4
0
        public ResponseObject Post([FromBody]UserDto userInfo)
        {
            if (string.IsNullOrEmpty(userInfo.OldPassword) || string.IsNullOrEmpty(userInfo.NewPassword))
            {
                ResponseObject.Failure("Old and new passwords are required");
            }

            var userService = new UserService();
            var user = userService.FindByNameAndPassword(User.Identity.Name, userInfo.OldPassword);
            if (user == null)
                return ResponseObject.Failure("Old password is incorrect");

            userService.Update(user.Id, userInfo.NewPassword);
            return ResponseObject.Success("");
        }
Exemplo n.º 5
0
        // GET api/training - get next card for training
        public ResponseObject Get()
        {
            var currentUser = new UserService().FindByName(User.Identity.Name);
            var cardService = new CardService();
            var total = cardService.Count(currentUser.Id);

            var drillService = new DrillService();
            var cards = drillService.GetCardsForDrill(currentUser.Id);

            var currentCard = new Card();
            if (cards.Count > 0)
            {
                currentCard = cards[0];
            }

            return ResponseObject.Success(new TrainingDto(currentCard, total, cards.Count));
        }
Exemplo n.º 6
0
        // PUT api/training/5 - update card
        public void Put(string id, [FromBody]byte answer)
        {
            var currentUser = new UserService().FindByName(User.Identity.Name);
            var cardFromService = new CardService().GetCardByID(id);
            if (cardFromService == null)
            {
                return;
            }

            var score = Score.None;
            if (answer > 2 && answer < 6)
            {
                score = (Score)answer;
            }

            Algorithm.GetUpdatedCard(cardFromService, score);
            var drillService = new DrillService();
            drillService.UpdateCard(cardFromService, currentUser.Id);
        }
Exemplo n.º 7
0
 //PUT - update card
 //public long Put(string id, [FromBody]CardDto card)
 //{
 //    var currentUser = new UserService().FindByName(User.Identity.Name);
 //    new CardService().Save(card.ID, card.Word, card.Translation, currentUser);
 //    return 0;
 //}
 // DELETE api/<controller>/5 - delete card
 public void Delete(string id)
 {
     var currentUser = new UserService().FindByName(User.Identity.Name);
     new CardService().Delete(id, currentUser.Id);
 }
Exemplo n.º 8
0
 public AuthorizationController()
 {
     _userService = new UserService();
 }