Beispiel #1
0
        public async Task <IActionResult> EditTutorName(long id, string TutorName)
        {
            using (var txscope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    var result = _tutorService.GetSingle(x => x.Id == id);
                    result.TutorName = TutorName;
                    var updateResult = await _tutorService.UpdateAsync(result, Accessor, User.GetUserId());

                    if (updateResult != null)
                    {
                        //StaffLog
                        if (User.IsInRole(UserRoles.Staff))
                        {
                            await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = ResponseConstants.UpdateTutorName }, Accessor, User.GetUserId());
                        }
                        txscope.Complete();
                        return(JsonResponse.GenerateJsonResult(1, ResponseConstants.UpdateTutorName));
                    }
                    else
                    {
                        txscope.Dispose();
                        return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                    }
                }
                catch (Exception ex)
                {
                    txscope.Dispose();
                    ErrorLog.AddErrorLog(ex, "EditTutorName");
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
            }
        }
        public async Task <IActionResult> RemovLesson(long[] id)
        {
            using (var txscope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    foreach (var item in id)
                    {
                        var lessonObj = _lessonService.GetSingle(x => x.Id == item);
                        if (lessonObj.Id != 0)
                        {
                            lessonObj.IsDelete = true;
                            await _lessonService.UpdateAsync(lessonObj, Accessor, User.GetUserId());

                            _gradeService.Save();
                        }
                    }

                    //StaffLog
                    if (User.IsInRole(UserRoles.Staff))
                    {
                        await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = ResponseConstants.DeleteLesson }, Accessor, User.GetUserId());
                    }
                    txscope.Complete();
                    return(JsonResponse.GenerateJsonResult(1, ResponseConstants.DeleteLesson));
                }
                catch (Exception ex)
                {
                    txscope.Dispose();
                    ErrorLog.AddErrorLog(ex, "Post-RemovLesson");
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
            }
        }
Beispiel #3
0
        public async Task <IActionResult> TutorPaymentRegister(PaymentDto model)
        {
            using (var txscope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    if (!ModelState.IsValid)
                    {
                        txscope.Dispose();
                        return(RedirectToAction("Index"));
                    }

                    if (model.Id == 0)
                    {
                        model.CreatedDate = DateTime.UtcNow;
                        var userResult = _userService.GetSingle(x => x.UserName == model.UserName.Trim());
                        if (userResult != null)
                        {
                            var tutorResult = _tutorService.GetSingle(x => x.TutorName == model.TutorName.Trim() && x.UserId == userResult.Id);
                            if (tutorResult != null)
                            {
                                model.TutorId = tutorResult.Id;
                            }
                        }

                        var PaymentObj = Mapper.Map <Payments>(model);
                        PaymentObj.IsActive = true;

                        var result = await _paymentService.InsertAsync(PaymentObj, Accessor, User.GetUserId());

                        if (result != null)
                        {
                            //StaffLog
                            if (User.IsInRole(UserRoles.Staff))
                            {
                                await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = ResponseConstants.SuccessPayment }, Accessor, User.GetUserId());
                            }

                            txscope.Complete();
                            return(JsonResponse.GenerateJsonResult(1, ResponseConstants.SuccessPayment));
                        }
                    }

                    else
                    {
                        txscope.Dispose();
                        return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                    }

                    txscope.Dispose();
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
                catch (Exception ex)
                {
                    txscope.Dispose();
                    ErrorLog.AddErrorLog(ex, "post/TutorPaymentRegister");
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
            }
        }
        public async Task <IActionResult> EditPassword(StudentDto model)
        {
            using (var txscope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    var result     = _studentService.GetSingle(x => x.Id == model.Id);
                    var userResult = _userService.GetSingle(x => x.Id == result.UserId);
                    userResult.PasswordHash = model.UserPassword;
                    var updateResult = await _userService.UpdateAsync(userResult, Accessor, User.GetUserId());

                    if (updateResult != null)
                    {
                        //StaffLog
                        if (User.IsInRole(UserRoles.Staff))
                        {
                            await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = ResponseConstants.UpdateStudentPassword }, Accessor, User.GetUserId());
                        }
                        txscope.Complete();
                        return(JsonResponse.GenerateJsonResult(1, ResponseConstants.UpdateStudentPassword));
                    }
                    else
                    {
                        txscope.Dispose();
                        return(JsonResponse.GenerateJsonResult(1, ResponseConstants.SomethingWrong));
                    }
                }
                catch (Exception ex)
                {
                    txscope.Dispose();
                    ErrorLog.AddErrorLog(ex, "EditStudentPassword");
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
            }
        }
Beispiel #5
0
        public async Task <IActionResult> DeleteLesson(long id)
        {
            using (var txscope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    var category = _lessonService.GetSingle(x => x.Id == id);
                    category.IsDelete = true;
                    await _lessonService.UpdateAsync(category, Accessor, User.GetUserId());

                    //StaffLog
                    if (User.IsInRole(UserRoles.Staff))
                    {
                        await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = ResponseConstants.DeleteGrade }, Accessor, User.GetUserId());
                    }
                    txscope.Complete();
                    return(JsonResponse.GenerateJsonResult(1, ResponseConstants.DeleteGrade));
                }
                catch (Exception ex)
                {
                    txscope.Dispose();
                    ErrorLog.AddErrorLog(ex, "Get-DeleteLesson");
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
            }
        }
        public async Task <IActionResult> RemoveExamQuestion(long QuestionId)
        {
            using (var txscope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    var questionObj = _examQuestionService.GetSingle(x => x.Id == QuestionId);
                    questionObj.IsDelete = true;
                    await _examQuestionService.UpdateAsync(questionObj, Accessor, User.GetUserId());


                    //StaffLog
                    if (User.IsInRole(UserRoles.Staff))
                    {
                        await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.Now, StaffId = User.GetUserId(), Description = ResponseConstants.DeleteExamQuestion }, Accessor, User.GetUserId());
                    }
                    txscope.Complete();

                    return(JsonResponse.GenerateJsonResult(1, ResponseConstants.DeleteExamQuestion));
                }
                catch (Exception ex)
                {
                    txscope.Dispose();
                    ErrorLog.AddErrorLog(ex, "Post-RemoveExamQuestion");
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
            }
        }
Beispiel #7
0
        public async Task <IActionResult> ManageSubscriptionIsActive(long id)
        {
            try
            {
                var subscriptionObj = _subscriptionService.GetSingle(x => x.Id == id);
                subscriptionObj.IsActive = !subscriptionObj.IsActive;
                await _subscriptionService.UpdateAsync(subscriptionObj, Accessor, User.GetUserId());

                var subscriptionTypeObj = _subscriptionTypeService.GetSingle(x => x.Id == subscriptionObj.SubscriptionTypeId);
                subscriptionTypeObj.IsActive = !subscriptionTypeObj.IsActive;
                var updateResult = await _subscriptionTypeService.UpdateAsync(subscriptionTypeObj, Accessor, User.GetUserId());

                if (updateResult != null)
                {
                    //StaffLog
                    if (User.IsInRole(UserRoles.Staff))
                    {
                        await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = $@"Subscription {(subscriptionObj.IsActive ? "activated" : "deactivated")} successfully." }, Accessor, User.GetUserId());
                    }
                    return(JsonResponse.GenerateJsonResult(1, $@"Subscription {(subscriptionObj.IsActive ? "activated" : "deactivated")} successfully."));
                }
                else
                {
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
            }
            catch (Exception ex)
            {
                ErrorLog.AddErrorLog(ex, "Post-/Subscription/ManageSubscriptionIsActive");
                return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
            }
        }
        public async Task <IActionResult> EditStudentMemberShipStatus(long id, bool IsMemberStatus)
        {
            using (var txscope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    //var result = _studentService.GetSingle(x => x.Id == id);
                    //var updateResult = await _studentService.UpdateAsync(result, Accessor, User.GetUserId());
                    //if (updateResult != null)
                    //{
                    //    //StaffLog
                    //    if (User.IsInRole(UserRoles.Staff))
                    //        await _staffLog.InsertAsync(new Log { StaffId = User.GetUserId(), Description = ResponseConstants.StudentMembeshipStatusUpdated }, Accessor, User.GetUserId());
                    //    txscope.Complete();
                    //    return JsonResponse.GenerateJsonResult(1, ResponseConstants.StudentMembeshipStatusUpdated);
                    //}
                    //else
                    //{
                    //    txscope.Dispose();
                    //    return JsonResponse.GenerateJsonResult(1, ResponseConstants.SomethingWrong);
                    //}

                    //New changes 06-10-2020
                    var result = _membershipService.GetSingle(x => x.StudentId == id);
                    if (result != null)
                    {
                        result.MembershipStatus = IsMemberStatus;
                    }
                    var updateResult = await _membershipService.UpdateAsync(result, Accessor, User.GetUserId());

                    if (updateResult != null)
                    {
                        //StaffLog
                        if (User.IsInRole(UserRoles.Staff))
                        {
                            await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = ResponseConstants.StudentMembeshipStatusUpdated }, Accessor, User.GetUserId());
                        }
                        txscope.Complete();
                        return(JsonResponse.GenerateJsonResult(1, ResponseConstants.StudentMembeshipStatusUpdated));
                    }
                    else
                    {
                        txscope.Dispose();
                        return(JsonResponse.GenerateJsonResult(1, ResponseConstants.SomethingWrong));
                    }
                }
                catch (Exception ex)
                {
                    txscope.Dispose();
                    ErrorLog.AddErrorLog(ex, "EditStudentNoOfDays");
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
            }
        }
        public async Task <IActionResult> Login([FromBody] LoginModel inputModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(_jsonResponse.GenerateJsonResult(false, "Invalid Model"));
                }

                var result = await _signInManager.PasswordSignInAsync(inputModel.Email, inputModel.Password, false, false);

                if (!result.Succeeded)
                {
                    return(_jsonResponse.GenerateJsonResult(false, "Invalid Login"));
                }

                var user = await _userManager.FindByEmailAsync(inputModel.Email);

                var roles = await _userManager.GetRolesAsync(user);

                var role = (Role)Enum.Parse(typeof(Role), roles[0]);

                if (!user.EmailConfirmed)
                {
                    return(_jsonResponse.GenerateJsonResult(false, "Please Confirm Your Email!!!"));
                }

                var currHttpScheme = _httpContext.HttpContext.Request.Scheme;
                var currHost       = _httpContext.HttpContext.Request.Host.Value;
                var currHostUrl    = currHttpScheme + "://" + currHost;

                var data = GenerateToken(roles, user, (int)role, currHostUrl);

                return(_jsonResponse.GenerateJsonResult(true, "Login Successfully", data));
            }
            catch (Exception ex)
            {
                var error = ex;
                return(_jsonResponse.GenerateJsonResult(false));
            }
        }
        public async Task <IActionResult> EditStudentNoOfDays(long id, int NoOfDays)
        {
            using (var txscope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    var subscriptionData = _subscriptionTypeService.GetSingle(x => x.TypeId == id);
                    if (subscriptionData != null)
                    {
                        subscriptionData.AllowedDays = NoOfDays;
                        var updateResult = await _subscriptionTypeService.UpdateAsync(subscriptionData, Accessor, User.GetUserId());

                        if (updateResult != null)
                        {
                            //Membership new changes 06-10-2020
                            var membershipData = _membershipService.GetSingle(x => x.StudentId == id);
                            if (membershipData != null)
                            {
                                membershipData.ExprireDate = DateTime.UtcNow.AddDays(NoOfDays);
                            }
                            if (membershipData.ExprireDate > DateTime.Now)
                            {
                                membershipData.MembershipStatus = true;//For Member Student
                            }
                            if (membershipData.ExprireDate <= DateTime.Now)
                            {
                                membershipData.MembershipStatus = false;//For Non-Member Student
                            }
                            //End

                            //StaffLog
                            if (User.IsInRole(UserRoles.Staff))
                            {
                                await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = ResponseConstants.StudentMembeshipNoOfDaysUpdated }, Accessor, User.GetUserId());
                            }
                            txscope.Complete();
                        }
                        else
                        {
                            txscope.Dispose();
                            return(JsonResponse.GenerateJsonResult(1, ResponseConstants.SomethingWrong));
                        }
                    }
                    return(JsonResponse.GenerateJsonResult(1, ResponseConstants.StudentMembeshipNoOfDaysUpdated));
                }
                catch (Exception ex)
                {
                    txscope.Dispose();
                    ErrorLog.AddErrorLog(ex, "EditStudentNoOfDays");
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
            }
        }
Beispiel #11
0
 public IActionResult GetOwnersList()
 {
     try
     {
         var result = _owner.GetAll().ToList();
         return(_jsonResponse.GenerateJsonResult(1, "Get List Successfully", new DatatableResponseHelper
         {
             TotalElements = result.Count,
             Data = result
         }));
     }
     catch (Exception ex)
     {
         return(_jsonResponse.GenerateJsonResult(0));
     }
 }
Beispiel #12
0
 public IActionResult GetPetsList()
 {
     try
     {
         var result = _pet.GetAll(x => x.Id != 0, false, x => x.Owner).Select(x => new
         {
             x.Id,
             x.owner_id,
             owner = x.Owner.FullName ?? "",
             x.type,
             x.name,
             x.age
         }).ToList();
         return(_jsonResponse.GenerateJsonResult(1, "Get List Successfully", new DatatableResponseHelper
         {
             Data = result
         }));
     }
     catch (Exception ex)
     {
         return(_jsonResponse.GenerateJsonResult(0));
     }
 }
        public async Task <IActionResult> AddEditMessage(MessageDto model)
        {
            using (var txscope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    if (!ModelState.IsValid)
                    {
                        txscope.Dispose();
                        return(RedirectToAction("Index", model.Id));
                    }

                    if (model.Id == 0)
                    {
                        model.CreatedDate = DateTime.UtcNow;
                        model.UserId      = User.GetUserId();
                        var messageObj = Mapper.Map <Message>(model);
                        messageObj.IsActive = true;
                        var result = await _messageService.InsertAsync(messageObj, Accessor, User.GetUserId());

                        if (result != null)
                        {
                            //SMSApiCalling(model);
                            //StaffLog
                            if (User.IsInRole(UserRoles.Staff))
                            {
                                await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = ResponseConstants.CreateMessage }, Accessor, User.GetUserId());
                            }
                            txscope.Complete();
                            return(JsonResponse.GenerateJsonResult(1, ResponseConstants.CreateMessage));
                        }
                    }
                    else
                    {
                        txscope.Dispose();
                        return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                    }

                    txscope.Dispose();
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
                catch (Exception ex)
                {
                    txscope.Dispose();
                    ErrorLog.AddErrorLog(ex, "CreateMessage");
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
            }
        }
        public async Task <IActionResult> ManageStudentIsActive(long id)
        {
            try
            {
                var studentObj = _studentService.GetSingle(x => x.Id == id);
                studentObj.IsActive = !studentObj.IsActive;
                await _studentService.UpdateAsync(studentObj, Accessor, User.GetUserId());

                return(JsonResponse.GenerateJsonResult(1, $@"Student {(studentObj.IsActive ? "activated" : "deactivated")} successfully."));
            }
            catch (Exception ex)
            {
                ErrorLog.AddErrorLog(ex, "Post-/Student/ManageStudentIsActive");
                return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
            }
        }
        public async Task <IActionResult> ManageFriendsIsActive(long id)
        {
            try
            {
                var FriendObj = _friendsService.GetSingle(x => x.Id == id);
                FriendObj.IsActive = !FriendObj.IsActive;
                await _friendsService.UpdateAsync(FriendObj, Accessor, User.GetUserId());

                return(JsonResponse.GenerateJsonResult(1, $@"Friends {(FriendObj.IsActive ? "activated" : "deactivated")} successfully."));
            }
            catch (Exception ex)
            {
                ErrorLog.AddErrorLog(ex, "Post-/Friend/ManageFriendsIsActive");
                return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
            }
        }
Beispiel #16
0
        public async Task <IActionResult> EditTutorMoNumber(long id, string Monumber)
        {
            using (var txscope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    if (!string.IsNullOrEmpty(Monumber))
                    {
                        bool mobileNoExist = MobileNoExists(Monumber);
                        if (mobileNoExist == true)
                        {
                            txscope.Dispose();
                            return(JsonResponse.GenerateJsonResult(3, ResponseConstants.MobileNoExist));
                        }
                        else
                        {
                            var result          = _tutorService.GetSingle(x => x.Id == id);
                            var tutorUserResult = _userService.GetSingle(x => x.Id == result.UserId);
                            tutorUserResult.MobileNumber = Monumber;
                            var updateResult = await _userService.UpdateAsync(tutorUserResult, Accessor, User.GetUserId());

                            if (updateResult != null)
                            {
                                //StaffLog
                                if (User.IsInRole(UserRoles.Staff))
                                {
                                    await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = ResponseConstants.UpdateTutorMobileNumber }, Accessor, User.GetUserId());
                                }
                                txscope.Complete();
                                return(JsonResponse.GenerateJsonResult(1, ResponseConstants.UpdateTutorMobileNumber));
                            }
                        }
                    }
                    txscope.Dispose();
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
                catch (Exception ex)
                {
                    txscope.Dispose();
                    ErrorLog.AddErrorLog(ex, "EditTutorMoNumber");
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
            }
        }
        public async Task <IActionResult> EditStudentGrade(long id, long gradeId)
        {
            using (var txscope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    var result = _studentService.GetSingle(x => x.Id == id && x.IsDelete == false && x.IsActive == true);
                    if (result != null)
                    {
                        result.GradeId = gradeId;
                        var updateResult = await _studentService.UpdateAsync(result, Accessor, User.GetUserId());

                        if (updateResult != null)
                        {
                            //StaffLog
                            if (User.IsInRole(UserRoles.Staff))
                            {
                                await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = ResponseConstants.UpdateStudentGrade }, Accessor, User.GetUserId());
                            }
                            txscope.Complete();
                            return(JsonResponse.GenerateJsonResult(1, ResponseConstants.UpdateStudentGrade));
                        }
                        else
                        {
                            txscope.Dispose();
                            return(JsonResponse.GenerateJsonResult(1, ResponseConstants.SomethingWrong));
                        }
                    }
                    else
                    {
                        return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                    }
                }
                catch (Exception ex)
                {
                    txscope.Dispose();
                    ErrorLog.AddErrorLog(ex, "EditStudentPassword");
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
            }
        }
Beispiel #18
0
        public async Task <IActionResult> Removetutors(long[] id)
        {
            using (var txscope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    foreach (var item in id)
                    {
                        var tutorObj = _tutorService.GetSingle(x => x.Id == item);
                        if (tutorObj.Id != 0)
                        {
                            tutorObj.IsDelete = true;
                            await _tutorService.UpdateAsync(tutorObj, Accessor, User.GetUserId());

                            _tutorService.Save();
                            var relevantObj = _relevantLessonService.GetAll().Where(x => x.TutorId == item);
                            foreach (var deleteObj in relevantObj)
                            {
                                await _relevantLessonService.DeleteAsync(deleteObj, Accessor, User.GetUserId());

                                await _relevantLessonService.SaveAsync();
                            }
                        }
                    }

                    //StaffLog
                    if (User.IsInRole(UserRoles.Staff))
                    {
                        await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = ResponseConstants.DeleteTutor }, Accessor, User.GetUserId());
                    }
                    txscope.Complete();
                    return(JsonResponse.GenerateJsonResult(1, ResponseConstants.DeleteTutor));
                }
                catch (Exception ex)
                {
                    txscope.Dispose();
                    ErrorLog.AddErrorLog(ex, "Post-Tutor Delete");
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
            }
        }
        public async Task <IActionResult> ManageGradeIsActive(long id)
        {
            try
            {
                var gradeObj = _gradeService.GetSingle(x => x.Id == id);
                gradeObj.IsActive = !gradeObj.IsActive;
                await _gradeService.UpdateAsync(gradeObj, Accessor, User.GetUserId());

                //StaffLog
                if (User.IsInRole(UserRoles.Staff))
                {
                    await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = "Grade Status Updated." }, Accessor, User.GetUserId());
                }
                return(JsonResponse.GenerateJsonResult(1, $@"Grade {(gradeObj.IsActive ? "activated" : "deactivated")} successfully."));
            }
            catch (Exception ex)
            {
                ErrorLog.AddErrorLog(ex, "Post-/Grade/ManageGradeIsActive");
                return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
            }
        }
        public async Task <IActionResult> RemovGrades(long id)
        {
            using (var txscope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    var gradeObj = _gradeService.GetSingle(x => x.Id == id);
                    if (gradeObj.Id != 0)
                    {
                        //removing lesson for this  grade

                        var lessonObjList = _lessonService.GetAll(x => x.GradeId == gradeObj.Id);
                        foreach (var lesson in lessonObjList)
                        {
                            lesson.IsDelete = true;
                            await _lessonService.UpdateAsync(lesson, Accessor, User.GetUserId());
                        }

                        gradeObj.IsDelete = true;
                        await _gradeService.UpdateAsync(gradeObj, Accessor, User.GetUserId());

                        _gradeService.Save();
                    }

                    //StaffLog
                    if (User.IsInRole(UserRoles.Staff))
                    {
                        await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = ResponseConstants.DeleteGrade }, Accessor, User.GetUserId());
                    }
                    txscope.Complete();
                    return(JsonResponse.GenerateJsonResult(1, ResponseConstants.DeleteGrade));
                }
                catch (Exception ex)
                {
                    txscope.Dispose();
                    ErrorLog.AddErrorLog(ex, "Post-DeleteDistributorRequest");
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
            }
        }
Beispiel #21
0
        public async Task <IActionResult> EditLesson(TutorDto model)
        {
            using (var txscope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    //string[] lessonIds = model.RelevantLesson.Split(",");
                    List <long> lessonIds = JsonConvert.DeserializeObject <List <long> >(model.RelevantLesson);

                    var relevantTutor = _relevantLessonService.GetAll().Where(x => x.TutorId == model.Id).ToList();
                    foreach (var item in relevantTutor)
                    {
                        await _relevantLessonService.DeleteAsync(item, Accessor, User.GetUserId());
                    }
                    foreach (var lesson in lessonIds)
                    {
                        var relevantLessonData = new RelevantLessonDto()
                        {
                            TutorId  = model.Id,
                            LessonId = lesson
                        };
                        var relevantLessonObj    = Mapper.Map <TutorRelevantLesson>(relevantLessonData);
                        var relevantLessonResult = await _relevantLessonService.InsertAsync(relevantLessonObj, Accessor, User.GetUserId());
                    }
                    //StaffLog
                    if (User.IsInRole(UserRoles.Staff))
                    {
                        await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = ResponseConstants.UpdateTutorRelevantLesson }, Accessor, User.GetUserId());
                    }
                    txscope.Complete();
                    return(JsonResponse.GenerateJsonResult(1, ResponseConstants.UpdateTutorRelevantLesson));
                }
                catch (Exception ex)
                {
                    txscope.Dispose();
                    ErrorLog.AddErrorLog(ex, "EditStudentPassword");
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
            }
        }
        public async Task <IActionResult> RemoveExam(long id)
        {
            using (var txscope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    var examObj = _examService.GetSingle(x => x.Id == id);
                    if (examObj.Id != 0)
                    {
                        //removing questions for this  exam

                        var QuestionObjList = _examQuestionService.GetAll(x => x.ExamId == examObj.Id);
                        foreach (var question in QuestionObjList)
                        {
                            question.IsDelete = true;
                            await _examQuestionService.UpdateAsync(question, Accessor, User.GetUserId());
                        }

                        examObj.IsDelete = true;
                        await _examService.UpdateAsync(examObj, Accessor, User.GetUserId());

                        _examService.Save();
                    }
                    //StaffLog
                    if (User.IsInRole(UserRoles.Staff))
                    {
                        await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.Now, StaffId = User.GetUserId(), Description = ResponseConstants.DeleteExam }, Accessor, User.GetUserId());
                    }
                    txscope.Complete();
                    return(JsonResponse.GenerateJsonResult(1, ResponseConstants.DeleteExam));
                }
                catch (Exception ex)
                {
                    txscope.Dispose();
                    ErrorLog.AddErrorLog(ex, "Post-RemoveExam");
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
            }
        }
        public async Task <IActionResult> DeleteStaff(long id)
        {
            using (var txscope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    var staffUser = _userManager.FindByIdAsync(id.ToString()).Result;
                    staffUser.IsActive = !staffUser.IsActive;
                    var UpdateResult = await _userManager.UpdateAsync(staffUser);

                    // var removeRoleResult = await _userManager.RemoveFromRoleAsync(staffUser, UserRoles.Staff);
                    if (UpdateResult.Succeeded)
                    {
                        var staff = _staff.GetSingle(x => x.UserId == id);
                        staff.IsActive = !staff.IsActive;
                        var staffUpdate = await _staff.UpdateAsync(staff, Accessor, User.GetUserId());

                        if (staffUpdate != null)
                        {
                            if (User.IsInRole(UserRoles.Staff))
                            {
                                await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = staffUser.IsActive ? ResponseConstants.ActivatedStaff : ResponseConstants.DeactivatedStaff }, Accessor, User.GetUserId());
                            }
                            txscope.Complete();
                            return(JsonResponse.GenerateJsonResult(1, staffUser.IsActive? ResponseConstants.ActivatedStaff : ResponseConstants.DeactivatedStaff));
                        }
                    }
                    txscope.Dispose();
                    return(JsonResponse.GenerateJsonResult(1, ResponseConstants.StaffDeletionError));
                }
                catch (Exception ex)
                {
                    txscope.Dispose();
                    ErrorLog.AddErrorLog(ex, "Post-DeleteStaff");
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
            }
        }
        public async Task <IActionResult> EditStudentNoOfQuestions(long id, int NoOfQuestions)
        {
            using (var txscope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    var subscriptionData = _subscriptionTypeService.GetSingle(x => x.TypeId == id);
                    if (subscriptionData != null)
                    {
                        subscriptionData.AllowedQuestion = NoOfQuestions;
                        var updateResult = await _subscriptionTypeService.UpdateAsync(subscriptionData, Accessor, User.GetUserId());

                        if (updateResult != null)
                        {
                            //StaffLog
                            if (User.IsInRole(UserRoles.Staff))
                            {
                                await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = ResponseConstants.StudentMembeshipNoOfQuestionUpdated }, Accessor, User.GetUserId());
                            }
                            txscope.Complete();
                        }
                        else
                        {
                            txscope.Dispose();
                            return(JsonResponse.GenerateJsonResult(1, ResponseConstants.SomethingWrong));
                        }
                    }
                    return(JsonResponse.GenerateJsonResult(1, ResponseConstants.StudentMembeshipNoOfQuestionUpdated));
                }
                catch (Exception ex)
                {
                    txscope.Dispose();
                    ErrorLog.AddErrorLog(ex, "EditStudentNoOfQuestions");
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
            }
        }
        public async Task <IActionResult> AddEditLesson(LessonDto model)
        {
            using (var txscope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    if (!ModelState.IsValid)
                    {
                        txscope.Dispose();
                        return(RedirectToAction("AddEditLesson", model.Id));
                    }
                    #region LessonFile
                    string newLessonFile = string.Empty, newLicenseFile = string.Empty;
                    if (model.LessonFile != null)
                    {
                        newLessonFile = $@"lesson-{CommonMethod.GetFileName(model.LessonFile.FileName)}";
                        await CommonMethod.UploadFileAsync(HostingEnvironment.WebRootPath, FilePathListConstant.LessonFile, newLessonFile, model.LessonFile);
                    }
                    #endregion
                    if (model.Id == 0)
                    {
                        model.CreatedDate = DateTime.UtcNow;
                        model.FileName    = newLessonFile;
                        var gradeObj = Mapper.Map <Lessons>(model);
                        gradeObj.IsActive = true;
                        var result = await _lessonService.InsertAsync(gradeObj, Accessor, User.GetUserId());

                        if (result != null)
                        {
                            //StaffLog
                            if (User.IsInRole(UserRoles.Staff))
                            {
                                await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = ResponseConstants.CreateNewLesson }, Accessor, User.GetUserId());
                            }
                            txscope.Complete();
                            return(JsonResponse.GenerateJsonResult(1, ResponseConstants.CreateNewLesson));
                        }
                    }
                    else if (model != null)
                    {
                        var result = await _lessonService.GetSingleAsync(x => x.Id == model.Id);

                        result.Name     = model.Name;
                        result.FileName = newLessonFile;
                        await _lessonService.UpdateAsync(result, Accessor, User.GetUserId());

                        //StaffLog
                        if (User.IsInRole(UserRoles.Staff))
                        {
                            await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = ResponseConstants.UpdateLesson }, Accessor, User.GetUserId());
                        }
                        txscope.Complete();
                        return(JsonResponse.GenerateJsonResult(1, ResponseConstants.UpdateLesson));
                    }
                    else
                    {
                        txscope.Dispose();
                        return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                    }

                    txscope.Dispose();
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
                catch (Exception ex)
                {
                    txscope.Dispose();
                    ErrorLog.AddErrorLog(ex, "CreateGrade");
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
            }
        }
        public async Task <IActionResult> AddEditGrade(GradeDto model)
        {
            using (var txscope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    if (!ModelState.IsValid)
                    {
                        txscope.Dispose();
                        return(RedirectToAction("AddEditGrade", model.Id));
                    }

                    if (model.Id == 0)
                    {
                        model.CreatedDate = DateTime.UtcNow;
                        var gradeObj = Mapper.Map <Grades>(model);
                        gradeObj.IsActive = true;
                        var result = await _gradeService.InsertAsync(gradeObj, Accessor, User.GetUserId());

                        if (result != null)
                        {
                            //StaffLog
                            if (User.IsInRole(UserRoles.Staff))
                            {
                                await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = ResponseConstants.CreateNewGrade }, Accessor, User.GetUserId());
                            }
                            txscope.Complete();
                            return(JsonResponse.GenerateJsonResult(1, ResponseConstants.CreateNewGrade));
                        }
                    }
                    else if (model != null)
                    {
                        var result = await _gradeService.GetSingleAsync(x => x.Id == model.Id);

                        result.Name = model.Name;

                        await _gradeService.UpdateAsync(result, Accessor, User.GetUserId());

                        //StaffLog
                        if (User.IsInRole(UserRoles.Staff))
                        {
                            await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = ResponseConstants.UpdateGrade }, Accessor, User.GetUserId());
                        }
                        txscope.Complete();
                        return(JsonResponse.GenerateJsonResult(1, ResponseConstants.UpdateGrade));
                    }
                    else
                    {
                        txscope.Dispose();
                        return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                    }

                    txscope.Dispose();
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
                catch (Exception ex)
                {
                    txscope.Dispose();
                    ErrorLog.AddErrorLog(ex, "CreateGrade");
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
            }
        }
        public async Task <IActionResult> AddQuestion([FromForm] ExamDto model)
        {
            using (var txscope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    if (!ModelState.IsValid)
                    {
                        txscope.Dispose();
                        return(RedirectToAction("AddQuestion", model.Id));
                    }
                    #region LessonFile
                    string newExamFile = string.Empty, newLicenseFile = string.Empty;
                    if (model.ExamFile != null)
                    {
                        newExamFile = $@"Exam-{CommonMethod.GetFileName(model.ExamFile.FileName)}";
                        await CommonMethod.UploadFileAsync(HostingEnvironment.WebRootPath, FilePathListConstant.ExamFiles, newExamFile, model.ExamFile);
                    }
                    #endregion

                    if (model.QuestionId != 0)
                    {
                        var examQuestionObj = _examQuestionService.GetSingle(x => x.Id == model.QuestionId);
                        examQuestionObj.Question = model.Question;
                        examQuestionObj.Answer   = model.Answer;
                        examQuestionObj.FileName = newExamFile;
                        var questionUpdateResult = await _examQuestionService.UpdateAsync(examQuestionObj, Accessor, User.GetUserId());

                        if (questionUpdateResult != null)
                        {
                            var ExamLessonList = _examLessonService.GetAll(x => x.ExamQuestionId == questionUpdateResult.Id);
                            _examLessonService.DeleteRange(ExamLessonList);
                            _examLessonService.Save();
                            List <long> lessonIdList = JsonConvert.DeserializeObject <List <long> >(model.LessonIdList);
                            foreach (var lessonid in lessonIdList)
                            {
                                var ExamLesson = new ExamLessons();
                                ExamLesson.ExamQuestionId = questionUpdateResult.Id;
                                ExamLesson.LessonId       = lessonid;
                                var examLessonResult = await _examLessonService.InsertAsync(ExamLesson, Accessor, User.GetUserId());
                            }
                        }
                        //StaffLog
                        if (User.IsInRole(UserRoles.Staff))
                        {
                            await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.Now, StaffId = User.GetUserId(), Description = ResponseConstants.UpdateExamQuestion }, Accessor, User.GetUserId());
                        }
                        txscope.Complete();
                        return(JsonResponse.GenerateJsonResult(1, ResponseConstants.UpdateExamQuestion));
                    }
                    else
                    {
                        model.CreatedDate = DateTime.UtcNow;
                        ExamsQuestions eq = new ExamsQuestions();
                        eq.ExamId   = model.ExamId;
                        eq.IsActive = true;
                        eq.Question = model.Question;
                        eq.Answer   = model.Answer;
                        eq.FileName = newExamFile;
                        var result = await _examQuestionService.InsertAsync(eq, Accessor, User.GetUserId());

                        if (result != null)
                        {
                            //Adding Lessons to the Exams Questions
                            List <long> lessonList = JsonConvert.DeserializeObject <List <long> >(model.LessonIdList);

                            foreach (var lessonid in lessonList)
                            {
                                var ExamLesson = new ExamLessons();
                                ExamLesson.ExamQuestionId = result.Id;
                                ExamLesson.LessonId       = lessonid;
                                var examLessonResult = await _examLessonService.InsertAsync(ExamLesson, Accessor, User.GetUserId());
                            }

                            //StaffLog
                            if (User.IsInRole(UserRoles.Staff))
                            {
                                await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = ResponseConstants.CreateNewExamQuestion }, Accessor, User.GetUserId());
                            }
                            txscope.Complete();
                            return(JsonResponse.GenerateJsonResult(1, ResponseConstants.CreateNewExamQuestion));
                        }



                        txscope.Dispose();
                        return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                    }
                }
                catch (Exception ex)
                {
                    txscope.Dispose();
                    ErrorLog.AddErrorLog(ex, "AddQuestion");
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
            }
        }
        public async Task <IActionResult> AddorRemoveStaff(StaffDto model)
        {
            using (var txscope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    var  appUser = _userManager.FindByNameAsync(model.UserName).Result;
                    long staffId = 0;
                    if (appUser != null)
                    {
                        appUser.UserName     = model.UserName;
                        appUser.FirstName    = model.Name;
                        appUser.MobileNumber = model.Mobile;
                        var updateResult = await _userManager.UpdateAsync(appUser);

                        if (updateResult != null)
                        {
                            // await _userManager.RemovePasswordAsync(appUser);
                            // await _userManager.AddPasswordAsync(appUser, model.Password);
                            var staff = _staff.GetSingle(x => x.UserId == appUser.Id);
                            staff.JobTitle    = model.JobTitle;
                            staff.CreatedDate = Convert.ToDateTime(model.DateOfEmployment);

                            var staffResult = await _staff.UpdateAsync(staff, Accessor, User.GetUserId());
                            await ManageMenuAccess(model, staffResult.Id);

                            if (User.IsInRole(UserRoles.Staff))
                            {
                                await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = "Staff Updated" }, Accessor, User.GetUserId());
                            }
                            txscope.Complete();
                            return(JsonResponse.GenerateJsonResult(1, "Staff Updated"));
                        }
                        else
                        {
                            txscope.Dispose();
                            ErrorLog.AddErrorLog(null, "Error in Update Staff");
                            return(JsonResponse.GenerateJsonResult(1, ResponseConstants.SomethingWrong));
                        }
                    }
                    else
                    {
                        #region CreateStaff

                        ApplicationUser user = new ApplicationUser();
                        user.MobileNumber = model.Mobile;
                        user.FirstName    = model.Name;
                        user.UserName     = model.UserName;

                        user.IsActive = true;
                        var userResult = await _userManager.CreateAsync(user, model.Password);

                        if (userResult != null)
                        {
                            var staffObj = new Staff();
                            staffObj.JobTitle    = model.JobTitle;
                            staffObj.UserId      = user.Id;
                            staffObj.IsActive    = true;
                            staffObj.CreatedDate = Convert.ToDateTime(model.DateOfEmployment);
                            var staffResult = await _staff.InsertAsync(staffObj, Accessor, User.GetUserId());

                            staffId = staffResult.Id;
                            await ManageMenuAccess(model, staffId);

                            //Assign Staff Role
                            await _userManager.AddToRoleAsync(user, UserRoles.Staff);

                            if (User.IsInRole(UserRoles.Staff))
                            {
                                await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = "New Staff Created" }, Accessor, User.GetUserId());
                            }
                            txscope.Complete();
                            return(JsonResponse.GenerateJsonResult(1, "New Staff Created"));
                        }
                        else
                        {
                            txscope.Dispose();
                            ErrorLog.AddErrorLog(null, "Error in Create Staff");
                            return(JsonResponse.GenerateJsonResult(1, ResponseConstants.SomethingWrong));
                        }


                        #endregion
                    }
                }
                catch (Exception ex)
                {
                    txscope.Dispose();
                    ErrorLog.AddErrorLog(ex, "AddorRemoveStaff");
                    return(JsonResponse.GenerateJsonResult(1, ResponseConstants.SomethingWrong));
                }
            }
        }
        public async Task <IActionResult> AddSetting(SettingDto model)
        {
            using (var txscope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    if (!ModelState.IsValid)
                    {
                        txscope.Dispose();
                        return(RedirectToAction("Index"));
                    }
                    if (model.Id == 0)
                    {
                        model.UserId   = User.GetUserId();
                        model.IsActive = true;
                        var dataModel = Mapper.Map <Settings>(model);
                        var result    = await _settingService.InsertAsync(dataModel, Accessor, User.GetUserId());

                        if (result != null)
                        {
                            //StaffLog
                            if (User.IsInRole(UserRoles.Staff))
                            {
                                await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = ResponseConstants.SettingTextCreated }, Accessor, User.GetUserId());
                            }
                            txscope.Complete();
                            return(JsonResponse.GenerateJsonResult(1, ResponseConstants.SettingTextCreated));
                        }
                        else
                        {
                            txscope.Dispose();
                            ErrorLog.AddErrorLog(null, "Post-AddSettings");
                            return(JsonResponse.GenerateJsonResult(0, "Settings not added."));
                        }
                    }
                    else
                    {
                        var data = _settingService.GetSingle(x => x.Id == model.Id && x.IsDelete == false && x.IsActive == true);
                        data.Id     = model.Id;
                        data.Html   = model.Html;
                        data.Title  = model.Title;
                        data.UserId = User.GetUserId();
                        var updateResult = await _settingService.UpdateAsync(data, Accessor, User.GetUserId());

                        if (updateResult != null)
                        {
                            //StaffLog
                            if (User.IsInRole(UserRoles.Staff))
                            {
                                await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = ResponseConstants.SettingTextCreated }, Accessor, User.GetUserId());
                            }
                            txscope.Complete();
                            return(JsonResponse.GenerateJsonResult(1, ResponseConstants.SettingTextUpdated));
                        }
                        else
                        {
                            txscope.Dispose();
                            return(JsonResponse.GenerateJsonResult(1, ResponseConstants.SomethingWrong));
                        }
                    }
                }

                catch (Exception ex)
                {
                    txscope.Dispose();
                    ErrorLog.AddErrorLog(ex, "Post-AddSettings");
                    return(JsonResponse.GenerateJsonResult(0));
                }
            }
            #endregion
        }
        public async Task <IActionResult> AddEditInvitationCode(InvitationCodeDto model)
        {
            using (var txscope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    if (!ModelState.IsValid)
                    {
                        txscope.Dispose();
                        RedirectToAction("_AddEditInvitationCode", model.Id);
                    }

                    if (model.Id == 0)
                    {
                        var invitationCodeObj = Mapper.Map <InvitationCode>(model);
                        invitationCodeObj.IsActive              = true;
                        invitationCodeObj.NumberOfFreeDays      = model.NoOfFreeDays;
                        invitationCodeObj.NumberOfFreeQuestions = model.NoOfFreeQuestions;
                        invitationCodeObj.ExpirationDays        = model.ExpirationDays;

                        var result = await _invitationCodesService.InsertAsync(invitationCodeObj, Accessor, User.GetUserId());

                        if (result != null)
                        {
                            //StaffLog
                            if (User.IsInRole(UserRoles.Staff))
                            {
                                await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = ResponseConstants.CreateInvitaionCode }, Accessor, User.GetUserId());
                            }
                            txscope.Complete();
                            return(JsonResponse.GenerateJsonResult(1, ResponseConstants.CreateInvitaionCode));
                        }
                    }
                    else if (model != null)
                    {
                        var result = await _invitationCodesService.GetSingleAsync(x => x.Id == model.Id && x.IsActive == true && x.IsDelete == false);

                        result.NumberOfFreeDays      = model.NoOfFreeDays;
                        result.NumberOfFreeQuestions = model.NoOfFreeQuestions;
                        result.ExpirationDays        = model.ExpirationDays;
                        result.IsActive = true;
                        await _invitationCodesService.UpdateAsync(result, Accessor, User.GetUserId());


                        //StaffLog
                        if (User.IsInRole(UserRoles.Staff))
                        {
                            await _staffLog.InsertAsync(new Log { CreatedDate = DateTime.UtcNow, StaffId = User.GetUserId(), Description = ResponseConstants.UpdateInvitationCode }, Accessor, User.GetUserId());
                        }
                        txscope.Complete();
                        return(JsonResponse.GenerateJsonResult(1, ResponseConstants.UpdateInvitationCode));
                    }
                    else
                    {
                        txscope.Dispose();
                        return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                    }

                    txscope.Dispose();
                    return(JsonResponse.GenerateJsonResult(0, ResponseConstants.SomethingWrong));
                }
                catch (Exception ex)
                {
                    txscope.Dispose();
                    ErrorLog.AddErrorLog(ex, "CreateInvitationCodeSetUp");
                    return(Json(ResponseConstants.SomethingWrong));
                }
            }
        }