Example #1
0
        public bool VerifyOTP(string phoneNumber, string OTPCode)
        {
            tblOTP OTP            = new tblOTP();
            bool   verifiedStatus = false;

            try
            {
                OTP = _unitOfWork.OTPRepo.Get(o => o.PhoneNumber.Equals(phoneNumber)).FirstOrDefault();
                //OTP = (from _OTP in _unitOfWork.OTPRepo.Get(o => o.PhoneNumber.Equals(phoneNumber))
                //                    //join _refreshtokens in _unitOfWork.RefreshTokenRepo.Get() on _devices.DeviceId equals _refreshtokens.DeviceId
                //                    //where _devices.PhoneNumber == phoneNumber
                //                select new tblOTP
                //                {
                //                    OTPCode = _OTP.OTPCode
                //                }).FirstOrDefault();

                if (OTPCode == Convert.ToString(OTP.OTPCode))
                {
                    verifiedStatus = true;
                }
            }
            catch (Exception ex)
            {
                CustomLogger.SendExcepToDB(ex, "AuthRepository");
                CustomLogger.LogError(Convert.ToString("VerifyOTP in AuthRepository- " + ex.Message));
                throw;
            }
            return(verifiedStatus);
        }
Example #2
0
        public tblRefreshTokens GetRefreshTokenByDeviceID(string deviceId)
        {
            tblRefreshTokens tblDevice = new tblRefreshTokens();

            try
            {
                //UserDevicesEntity
                tblDevice = _unitOfWork.RefreshTokenRepo.Get(o => o.DeviceId.Equals(deviceId)).FirstOrDefault();
            }
            catch (Exception ex)
            {
                CustomLogger.LogError("Error in GetRefreshTokenByDeviceID  " + Convert.ToString(ex.Message));
                CustomLogger.SendExcepToDB(ex, "AuthRepository");
                throw;
            }

            ////===============Mapper===========================================
            //var config = new MapperConfiguration(cfg => {
            //    cfg.CreateMap<tblDevice, DevicesEntity>();
            //});

            //IMapper mapper = config.CreateMapper();
            //deviceEntity = mapper.Map<tblDevice, DevicesEntity>(patient);
            ////===============mapper end==========================================
            return(tblDevice);
        }
Example #3
0
        public async Task <ActionResult> ApproveAccessRequest(int accessRequestId)
        {
            try
            {
                //make request status approved
                var accessRequest = _accessRequestService.GetById(accessRequestId);

                if (accessRequest == null)
                {
                    return(Content("Access Request does not exist"));
                }

                _accessRequestService.AcceptRequest(accessRequestId);

                //create user
                var applicationUser = new ApplicationUser()
                {
                    FirstName   = accessRequest.FirstName,
                    LastName    = accessRequest.LastName,
                    Email       = accessRequest.Email,
                    Gender      = accessRequest.Gender,
                    Birthday    = accessRequest.Birthday,
                    DateCreated = DateTime.UtcNow,
                    PhoneNumber = accessRequest.PhoneNumber,
                    UserName    = accessRequest.Email,
                };

                string password = PasswordHelper.GenerateRandomPassword();
                var    result   = await UserManager.CreateAsync(applicationUser, password);

                //AddRole
                UserManager.AddToRole(applicationUser.Id, accessRequest.AspNetRole.Name);
                var callbackUrl = Url.Action("Login", "Account");
                await UserManager.SendEmailAsync(applicationUser.Id, "Your user request was approved",
                                                 "Login by going to this link <a href=\"http://localhost:2276/account/login \">here </a> with " +
                                                 password + " as a password");

                if (accessRequest.AspNetRole.Name == "Kitched Staff")
                {
                    _queueService.AddWorkforce(new KitchenStaff()
                    {
                        ID = applicationUser.Id, Name = applicationUser.UserName, Capacity = 3, Workload = new Queue <int>()
                    });                                                                                                                                                      /// uh?
                }

                if (accessRequest.AspNetRole.Name == "Delivery Service Staff")
                {
                    deliveryAutomation.AddWorkforce(applicationUser.Id);
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                CustomLogger.LogError("Cannot approve Access Request", e);
                return(new HttpStatusCodeResult(500));
            }
        }
Example #4
0
        public tblAppUser RegisterUser(DevicesEntity deviceModel)
        {
            bool flag = false;
            List <tblAppUser> user      = new List <tblAppUser>();
            List <tblDevice>  tblDevice = new List <tblDevice>();

            try
            {
                user = _unitOfWork.AppUserRepo.Get(c => c.PhoneNumber.Equals(deviceModel.PhoneNumber)).ToList();
                if (user.Count() > 0)
                {
                    tblDevice = _unitOfWork.DeviceRepo.Get(c => c.EmailId.Equals(deviceModel.EmailId) && c.PhoneNumber.Equals(deviceModel.PhoneNumber)).ToList();
                    if (tblDevice.Count() == 0)
                    {
                        using (var scope = new TransactionScope())
                        {
                            var TblDevice = new tblDevice
                            {
                                //Drowid = 1,
                                DeviceId    = deviceModel.DeviceId,
                                EmailId     = deviceModel.EmailId,
                                PhoneNumber = deviceModel.PhoneNumber,
                                SignPath    = deviceModel.SignPath,
                            };

                            _unitOfWork.DeviceRepo.Insert(TblDevice);
                            _unitOfWork.Save();
                            scope.Complete();
                        }
                    }

                    flag = true;
                }
                if (flag)
                {
                    return(user.FirstOrDefault());
                }
                else
                {
                    tblAppUser emptyUser = new tblAppUser();
                    return(emptyUser);
                }
            }
            catch (Exception ex)
            {
                CustomLogger.LogError("AuthRepository in RegisterUser " + Convert.ToString(ex.Message));
                CustomLogger.SendExcepToDB(ex, "AuthRepository");

                throw;
            }
            finally
            {
            }
        }
Example #5
0
    public static void TestFromOver()
    {
        CustomLogger.LogDebug("Testing: TestFromOver()");
        FizzBuzzModel fbm = new FizzBuzzModel(_config);

        try {
            fbm.getList(max + 1);
            CustomLogger.LogDebug("Testing: TestFromOver() unsuccessful, no exceptions found");
        } catch (CustomException e) {
            CustomLogger.LogError("Testing: TestFromOver() successful: " + e.Message);
        }
    }
Example #6
0
 public void Intercept(IInvocation invocation)
 {
     try
     {
         invocation.Proceed();
     }
     catch (Exception e)
     {
         CustomLogger.LogError(e.Message, e);
         throw new BaseException(666, e.Message, e);
     }
 }
Example #7
0
 public ActionResult ReviewAccessRequests()
 {
     try
     {
         var accessRequests = _accessRequestService.GetAllRequests();
         return(View(accessRequests));
     }
     catch (Exception e)
     {
         CustomLogger.LogError("Cannot get access requests", e);
         return(new HttpStatusCodeResult(500));
     }
 }
Example #8
0
 public void LogAppError(tblAppError AppError)
 {
     try
     {
         _unitOfWork.AppErrorsRepo.Insert(AppError);
         _unitOfWork.Save();
     }
     catch (Exception ex)
     {
         CustomLogger.LogError("CommonRepository in UpdateRefreshToken " + Convert.ToString(ex.Message));
         CustomLogger.SendExcepToDB(ex, "CommonRepository");
         throw;
     }
 }
        public string[] Get(int start)
        {
            CustomLogger.LogInformation("Get FizzBuzz list: " + start);

            string[] list;

            try {
                list = fbm.getList(start);
            } catch (CustomException e) {
                CustomLogger.LogError(e.Message);
                list = new string[] { "error, see log for details: " + CustomLogger.GetLogPath() };
            }

            return(list);
        }
 public ActionResult CreateAccessRequest()
 {
     try
     {
         var viewModel = new AccessRequestFromViewModel()
         {
             UserAccessRequests = new UsersAccessRequest(),
             AspNetRoles        = _rolesService.GetRolesForAccessRequest()
         };
         return(View(viewModel));
     }
     catch (Exception e)
     {
         CustomLogger.LogError("Cannot get access request viewmodel properties", e);
         return(new HttpStatusCodeResult(500));
     }
 }
Example #11
0
        public ActionResult AnonymizeAccount(int userId)
        {
            try
            {
                var userInDb = UserManager.FindById(userId);
                if (userInDb == null)
                {
                    return(HttpNotFound());
                }

                _userService.AnonimyzeUser(userId);
                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                CustomLogger.LogError("Aksnonymyzing account", e);
                return(new HttpStatusCodeResult(500));
            }
        }
Example #12
0
        /// <summary>
        /// Updates a product
        /// </summary>
        /// <param name="productId"></param>
        /// <param name="productEntity"></param>
        /// <returns></returns>
        public async Task <bool> UpdateRefreshToken(RefreshToken refreshToken)
        {
            var success = false;

            try
            {
                if (refreshToken != null)
                {
                    //  using (var scope = new TransactionScope())
                    // {
                    var rToken = _ctx.tblRefreshTokens.Find(refreshToken.Id);
                    //   rToken.VerificationCode = refreshToken.VarificationCode;
                    if (rToken != null)
                    {
                        rToken.Id              = refreshToken.Id;
                        rToken.Subject         = refreshToken.Subject;
                        rToken.ClientId        = refreshToken.ClientId;
                        rToken.IssuedUtc       = refreshToken.IssuedUtc;
                        rToken.ExpiresUtc      = refreshToken.ExpiresUtc;
                        rToken.ProtectedTicket = refreshToken.ProtectedTicket;


                        _ctx.tblRefreshTokens.Attach(rToken);
                        _ctx.Entry(rToken).State = EntityState.Modified;
                        success = await _ctx.SaveChangesAsync() > 0;

                        //  scope.Complete();
                        // success = true;
                        //}
                    }
                }
            }
            catch (Exception ex)
            {
                CustomLogger.LogError("AuthRepository in UpdateRefreshToken " + Convert.ToString(ex.Message));
                CustomLogger.SendExcepToDB(ex, "AuthRepository");

                throw;
            }
            return(success);
        }
Example #13
0
        public ActionResult DenyAccessRequest(int accessRequestId)
        {
            try
            {
                //make request status approved
                var accessRequest = _accessRequestService.GetById(accessRequestId);

                if (accessRequest == null)
                {
                    return(Content("Access Request does not exist"));
                }

                _accessRequestService.DenyRequest(accessRequestId);
                return(RedirectToAction("ReviewAccessRequests"));
            }
            catch (Exception e)
            {
                CustomLogger.LogError("Cannot deny access request", e);
                return(new HttpStatusCodeResult(500));
            }
        }
Example #14
0
        public bool UpdateDevices(tblOTP devices)
        {
            devices.IssuedUtc = DateTime.UtcNow;
            tblOTP otpEntity = new tblOTP();
            var    success   = false;

            try
            {
                if (devices != null)
                {
                    //  using (var scope = new TransactionScope())
                    // {
                    //var rToken = _ctx.tblDevices.Find(devices.PhoneNumber);
                    var rToken = _ctx.tblOTPs.Where(x => x.PhoneNumber == devices.PhoneNumber).FirstOrDefault();

                    // rToken.OTPCode = devices.OTPCode;
                    if (rToken != null)
                    {
                        rToken.OTPCode           = devices.OTPCode;
                        rToken.IssuedUtc         = DateTime.UtcNow;
                        _ctx.Entry(rToken).State = EntityState.Modified;
                        _ctx.SaveChanges();
                    }
                    else
                    {
                        _ctx.tblOTPs.Add(devices);
                        _ctx.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                CustomLogger.LogError("AuthRepository in UpdateDevices " + Convert.ToString(ex.Message));
                CustomLogger.SendExcepToDB(ex, "AuthRepository");
                throw;
            }

            return(success);
        }
        public ActionResult CreateAccessRequest(AccessRequestFromViewModel acccessRequestFromViewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var viewModel = new AccessRequestFromViewModel()
                    {
                        UserAccessRequests = acccessRequestFromViewModel.UserAccessRequests,
                        AspNetRoles        = _rolesService.GetRolesForAccessRequest()
                    };
                    return(View(viewModel));
                }

                //kontrollo nese useri ekziston tek tabelat e user ose user requests
                var userInDb             = UserManager.FindByEmail(acccessRequestFromViewModel.UserAccessRequests.Email);
                var userInAccessRequests = _accessRequestService.GetByEmail(acccessRequestFromViewModel.UserAccessRequests.Email);

                if (userInDb != null || userInAccessRequests != null)
                {
                    ModelState.AddModelError("", "Email already exists");
                    var viewModel = new AccessRequestFromViewModel()
                    {
                        UserAccessRequests = acccessRequestFromViewModel.UserAccessRequests,
                        AspNetRoles        = _rolesService.GetRolesForAccessRequest()
                    };
                    return(View(viewModel));
                }

                //krijo user request
                _accessRequestService.CreateAcessRequest(acccessRequestFromViewModel.UserAccessRequests);
                return(Content("Your request is sent successfully"));
            }
            catch (Exception e)
            {
                CustomLogger.LogError("Cannot create access request", e);
                return(new HttpStatusCodeResult(500));
            }
        }
Example #16
0
        public Task LogAsync(LogMessage msg)
        {
            // Variables declaration
            string message = msg.Exception?.ToString() ?? msg.Message;

            // Use different loggers for different severity levels
            switch (msg.Severity)
            {
            case LogSeverity.Critical:
                _logger.LogCritical(message);
                break;

            case LogSeverity.Error:
                _logger.LogError(message);
                break;

            case LogSeverity.Warning:
                _logger.LogWarning(message);
                break;

            case LogSeverity.Info:
                _logger.LogInformation(message);
                break;

            case LogSeverity.Debug:
                _logger.LogDebug(message);
                break;

            default:
                _logger.LogDefault(message);
                break;
            }

            // Log to filesystem.
            // W.I.P

            // Once all tasks have been completed, return 'Task.CompletedTask'
            return(Task.CompletedTask);
        }
Example #17
0
        // GET: Admin
        public ActionResult Index(bool showDisabled = false)
        {
            try
            {
                List <UserDto> users;
                if (!showDisabled)
                {
                    ViewBag.showDisabled = "false";
                    users = _userService.GetAllActiveUsers();
                    return(View("Index", users));
                }

                ViewBag.showDisabled = "true";
                users = _userService.GetAllInactiveUsers();
                return(View("Index", users));
            }
            catch (Exception e)
            {
                CustomLogger.LogError("Error getting inactive users", e);
                return(new HttpStatusCodeResult(500));
            }
        }
Example #18
0
    public static void TestAsync()
    {
        CustomLogger.LogDebug("Testing: TestAsync()");
        FizzBuzzModel fbm = new FizzBuzzModel(_config);

        Task[] tasks = new Task[max - 1];

        try {
            for (int i = 1; i < max; i++)
            {
                tasks[i - 1] = Task.Run(() => fbm.getList(i));
            }

            foreach (Task t in tasks)
            {
                t.Wait();
            }

            CustomLogger.LogDebug("Testing: TestAsync successful");
        } catch (Exception e) {
            CustomLogger.LogError("Testing: TestAsync() unsuccessful: " + e.Message);
        }
    }
Example #19
0
        public List <NotesSummaryEntity> GetNotesSummary(int patientId)
        {
            List <NotesSummaryEntity> notesSummary      = new List <NotesSummaryEntity>();
            List <NotesSummaryEntity> notesSummaryFinal = new List <NotesSummaryEntity>();

            Team.Rehab.DataModel.RehabEntities rehab = new RehabEntities();
            List <NotificationsEntity>         notificationsEntity = new List <NotificationsEntity>();

            try
            {
                notesSummary = (from notes in rehab.tblDocMasters.Where(a => a.PTrowid == patientId)
                                join thpst in rehab.tblTherapists on notes.TreatingTherapistId equals thpst.TherapistID
                                join clinic in rehab.tblClinics on thpst.DefaultClinic equals clinic.Crowid
                                join usr in rehab.tblUsers on
                                new { thpst.FirstName, thpst.LastName } equals new { usr.FirstName, usr.LastName }
                                select new NotesSummaryEntity
                {
                    Docrowid = notes.Docrowid,
                    NotesType = notes.NoteType,
                    DateOfService = notes.DateOfService,
                    FirstName = thpst.FirstName,
                    LastName = thpst.LastName,
                    //  TherpistPhone = thpst.TherpistPhone,
                    TherapistEmail = usr.UserEmail,
                    ClinicName = clinic.ClinicName,
                    ClinicPhone = clinic.PhoneNumber
                                  //  ClinicEmail = clinic.ClinicEmail,
                }
                                ).ToList();
                foreach (NotesSummaryEntity obj in notesSummary)
                {
                    if (obj.NotesType == "PPOC")
                    {
                        obj.NotesType = "Initial Eval";
                    }
                    if (obj.NotesType == "PPOC2")
                    {
                        obj.NotesType = "Initial Eval2";
                    }
                    if (obj.NotesType == "PPOCRE")
                    {
                        obj.NotesType = "Re-Eval";
                    }

                    if (obj.NotesType == "PTREAT")
                    {
                        obj.NotesType = "Daily Note";
                    }

                    if (obj.NotesType == "PMN")
                    {
                        obj.NotesType = "Medical Necessity";
                    }
                    if (obj.NotesType == "PDIS")
                    {
                        obj.NotesType = "Discharge";
                    }
                    if (obj.NotesType == "PCOMM")
                    {
                        obj.NotesType = "Communication";
                    }
                    if (obj.NotesType == "PMV")
                    {
                        obj.NotesType = "Missed";
                    }
                    if (obj.NotesType == "PFCE")
                    {
                        obj.NotesType = "FCE";
                    }

                    notesSummaryFinal.Add(obj);


                    //WHEN 'PFCE' then 'FCE'

                    //    Else 'Others'
                }
            }
            catch (Exception ex)
            {
                CustomLogger.SendExcepToDB(ex, "PatinetRepository");
                CustomLogger.LogError(Convert.ToString("NoteSummary in PatinetRepository- " + ex.Message));
            }
            return(notesSummaryFinal);
        }