예제 #1
0
        public async Task <bool> GenerateOtp(string uid, string toemail)
        {
            var    op        = _otps.AsQueryable().OrderByDescending(x => x.CreatedAt).Where(x => x.userId == ObjectId.Parse(uid) && x.status == "active").FirstOrDefault();
            Random generator = new Random();
            String r         = generator.Next(0, 1000000).ToString("D6");

            if (op == null)
            {
                await _otps.InsertOneAsync(new otp()
                {
                    CreatedAt = DateTime.Now,
                    otpvalue  = r,
                    status    = "active",
                    userId    = ObjectId.Parse(uid)
                });

                var res = EmailConfig.SendEmail("Confidential Mail", "One Time Password Is " + r + " Please don't Share it to any one", toemail, _email);
            }
            else
            {
                op.status = "deactive";
                await _otps.ReplaceOneAsync(op);

                await _otps.InsertOneAsync(new otp()
                {
                    CreatedAt = DateTime.Now,
                    otpvalue  = r,
                    status    = "active",
                    userId    = ObjectId.Parse(uid)
                });

                var res = EmailConfig.SendEmail("Confidential Mail", "One Time Password Is " + r + " Please don't Share it to any one", toemail, _email);
            }
            return(true);
        }
예제 #2
0
        public async Task <IActionResult> EditDevice([FromBody] EditDeviceSchema schema)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid Request"));
            }
            var res = await _device.ReplaceOneAsync(new Devices()
            {
                Id        = ObjectId.Parse(schema.Id),
                CreatedAt = DateTime.Now,
                mac       = schema.mac,
                name      = schema.name,
                userId    = schema.userId
            });

            if (res)
            {
                var usr = _user.Users.Where(x => x.UserName == schema.userId).FirstOrDefault();
                await _log.InsertOneAsync(
                    new Logs()
                {
                    userId    = usr.Id,
                    message   = "Device " + schema.name + " is Added Successfully",
                    events    = "Event",
                    subject   = "Insertion",
                    CreatedAt = DateTime.Now
                });

                return(Ok(new { status = "Device " + schema.name + " is Added Successfully" }));
            }
            return(BadRequest("Invalid Request"));
        }