public static void Register(HttpRequestBase req, HttpResponseBase res)
        {
            string firstName  = req["firstName"];
            string lastName   = req["lastName"];
            string city       = req["city"];
            bool   relocation = req["relocation"] == "true";
            string login      = req["login"];
            string password   = req["password"];
            var    image      = req.Files["image"];

            if (!_commonLogic.CheckLogin(login))
            {
                res.Write(JsonConvert.SerializeObject(new RequestResult("Error", "Login occupied.")));
                return;
            }

            var employee = new Employee
            {
                FirstName  = firstName,
                LastName   = lastName,
                City       = city,
                Relocation = relocation,
                Login      = login,
                Password   = Convert.ToBase64String(_sha256.ComputeHash(Encoding.Unicode.GetBytes(password))),
                Photo      = string.Empty
            };

            if (image != null && image.ContentLength != 0)
            {
                var bytes = new byte[image.ContentLength];
                image.InputStream.Read(bytes, 0, bytes.Length);
                employee.Photo = Convert.ToBase64String(bytes);
            }

            employee = _employeeLogic.Register(employee);
            if (employee.Id == 0)
            {
                res.Write(JsonConvert.SerializeObject(new RequestResult("Error", "Something went wrong.")));
                return;
            }
            else
            {
                res.Write(JsonConvert.SerializeObject(new RequestResult("Success", "Successfully registered.")));
                return;
            }
        }
示例#2
0
        public async Task <IActionResult> Register(EmployeeForLogin user)
        {
            user.Username = user.Username.ToLower();

            //if (await _logic.UserExists(user.Username))
            //    return BadRequest("Username already exists!");

            var userForRegistration = await _logic.GetObjectByUsername(user.Username);

            if (userForRegistration == null)
            {
                return(BadRequest($"Employee with username:'******' doesn't exist."));
            }

            var createdUser = await _logic.Register(userForRegistration, user.Password);

            return(StatusCode(201));
        }