コード例 #1
0
        public ActionResult <string> AddAddedPart([FromBody] addedPartDTO addedPartDTO)
        {
            try
            {
                BUser user = _bUserRepository.GetByEmail(addedPartDTO.email);
                Part  part = _partRepository.GetById(addedPartDTO.partId);


                if (user != null && part != null)
                {
                    _addedPartRepository.AddAddedPart(new AddedPart
                    {
                        Name  = addedPartDTO.name,
                        Brand = addedPartDTO.brand,
                        Price = addedPartDTO.price,
                        BUser = user,
                        Part  = part,
                        Link  = addedPartDTO.link
                    });
                    _addedPartRepository.SaveChanges();
                    AddedPart addedPart = _addedPartRepository.GetMostRecentByPartIdAndEmail(addedPartDTO.partId, addedPartDTO.email);
                    addedPartDTO.id = addedPart.Id;
                    return(Ok(addedPartDTO));
                }
                return(NotFound("This email address isn't know"));
            }
            catch (Exception e)
            {
                return(NotFound(e.Message));
            }
        }
コード例 #2
0
        public async Task <ActionResult <String> > CreateToken([FromBody] LoginDTO model)
        {
            var user = await _userManager.FindByNameAsync(model.Email);

            var bUser = _bUserRepository.GetByEmail(model.Email);

            if (user != null)
            {
                var result = await _signInManager.CheckPasswordSignInAsync(user, model.Password, false);

                if (result.Succeeded)
                {
                    string token = GetToken(user);
                    return(Created("", token));
                }
                else
                {
                    return(BadRequest("Email/Password combination wrong"));
                }
            }
            return(BadRequest("Not a know email"));
        }