示例#1
0
        public static async Task <IActionResult> RiderCreate([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req)
        {
            // req.IsValidToken();

            //Rider user = await req.Content.ReadAsAsync<Rider>();

            string requestBody = new StreamReader(req.Body).ReadToEnd();
            Rider  user        = JsonConvert.DeserializeObject <Rider>(requestBody);

            await RiderRepository <Rider> .Initialize();

            if (user == null)
            {
                return((ActionResult) new OkObjectResult("User cannot be null or empty"));
            }

            if (string.IsNullOrEmpty(user.Email))
            {
                return((ActionResult) new OkObjectResult("An email address is needed for this request"));
            }

            var udb = RiderRepository <Rider> .GetItems($"Select * from RiderData u where u.Email = '{user.Email}'");

            if (udb != null && udb.Count() > 0)
            {
                return((ActionResult) new OkObjectResult("Rider already exist, please login or activate account to continue"));
            }

            if (string.IsNullOrEmpty(user.Password))
            {
                return((ActionResult) new OkObjectResult("A Password is needed for this request"));
            }

            user.Password = user.Password.EncodeString();

            user.LastModified = DateTime.Now;

            user.IsActivated = true;

            try
            {
                dynamic u = await RiderRepository <Rider> .CreateItemAsync(user);

                return((ActionResult) new OkObjectResult("Your account has been created. Admin will contact via the number provided to complete the activation process."));
            }
            catch (Exception ex)
            {
                return((ActionResult) new OkObjectResult("An error has occured"));
            }
        }