Esempio n. 1
0
        public string Post([FromBody] Users value)
        {
            if (!dbContext.Users.Any(user => user.Login.Equals(value.Login)))
            {
                Users user = new Users();
                user.Name     = value.Name;
                user.Login    = value.Login;
                user.Password = value.Password;
                user.Phone    = value.Phone;
                user.Email    = value.Email;

                try
                {
                    dbContext.Add(user);
                    dbContext.SaveChanges();
                    return(JsonConvert.SerializeObject("User has been registered!"));
                }
                catch (Exception e)
                {
                    return(JsonConvert.SerializeObject(e.Message));
                }
            }
            else
            {
                return(JsonConvert.SerializeObject("User is existing!"));
            }
        }
Esempio n. 2
0
        public void Post([FromBody] Events value)
        {
            Events events = new Events();

            events.CId         = value.CId;
            events.Title       = value.Title;
            events.Description = value.Description;
            events.Date        = value.Date;

            try
            {
                dbContext.Add(events);
                dbContext.SaveChanges();
            }
            catch (Exception e)
            {
            }
        }
        public void Post([FromBody] Members value)
        {
            Members member = new Members();

            member.EventId = value.EventId;
            member.UId     = value.UId;

            try
            {
                dbContext.Add(member);
                dbContext.SaveChanges();
            }
            catch (Exception e)
            {
            }
        }
Esempio n. 4
0
        public IActionResult Register([FromBody] Register model)
        {
            // validation
            if (string.IsNullOrWhiteSpace(model.Password))
            {
                return(BadRequest(new { status = "error", message = "Password is required" }));
            }

            if (_context.Users.Any(x => x.Email == model.Email))
            {
                return(BadRequest(new { status = "error", message = "Email \"" + model.Email + "\" is already taken" }));
            }


            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(model.Password, out passwordHash, out passwordSalt);

            User user = new User();

            user.Name         = model.Name;
            user.Email        = model.Email;
            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            _context.Users.Add(user);
            _context.SaveChanges();
            var latestId = user.UserId;

            return(Ok(new
            {
                status = "success",
                message = "New user created",
                Name = user.Name,
                Email = user.Email
            }));
        }