Пример #1
0
        public async Task <IActionResult> HomeCompleteTask(WM_TaskComplete model)
        {
            var result = new MessageReport(false, "Có lỗi xảy ra");
            var user   = await SessionCookieHelper.CurrentUser(this.HttpContext);

            model.UserId = user != null ? user.UserId : "";

            try
            {
                //Lấy task
                var objTask = await _WM_TaskService.GetById(model.TaskId);

                if (objTask == null)
                {
                    result = new MessageReport(false, "Công việc của bạn không tồn tại");
                    return(Json(result));
                }

                //Task user
                var userTask = await _WM_TaskService.GetByTaskId_UserId(model.TaskId, model.UserId);

                if (userTask == null)
                {
                    result = new MessageReport(false, "Công việc của bạn không tồn tại");
                    return(Json(result));
                }

                //Check công việc hoàn thành
                userTask.IsCompleted   = true;
                userTask.DateCompleted = DateTime.Now;
                userTask.IsOnScheduled = true;

                if (userTask.DateCompleted > objTask.DateEnd)
                {
                    userTask.IsOnScheduled = false;
                }

                result = await _WM_TaskService.UpdateUserTask(userTask);

                if (result.isSuccess)
                {
                    var userTasks = await _WM_TaskService.GetUserTasksByTaskId(objTask.Id);

                    var userIds = userTasks.Select(n => n.UserId).ToList();
                    userIds.Add(objTask.UserCreatedId);

                    SendMessageComplete(objTask, userIds, model.UserId);

                    RemoveSchedule(objTask);
                }
            }
            catch (System.Exception ex)
            {
                result = new MessageReport(false, ex.Message);
            }

            return(Json(result));
        }
Пример #2
0
        public async Task <IActionResult> HomeDiaryPartial(string scheduleid)
        {
            //Lấy người dùng hiện tại
            var currentUser = await SessionCookieHelper.CurrentUser(this.HttpContext);

            var list = await _WM_DiaryService.GetAllByUserId_ScheduleId(currentUser != null?currentUser.UserId : "", scheduleid);

            return(PartialView(list));
        }
Пример #3
0
        private void ReadSessionHeaderInfo()
        {
            SessionHeaderInfo = SessionCookieHelper <ISessionHeaderInfo> .Get(Constants.SecurityKey.HeaderInfo_SessionName, Constants.SecurityKey.HeaderInfo_CookieName, Constants.SecurityKey.key, Constants.SecurityKey.IV);

            if (SessionHeaderInfo != null && !string.IsNullOrEmpty(Host) && string.Compare(SessionHeaderInfo.HeaderId, Host, true) != 0)
            {
                SessionHeaderInfo = null;
                SessionCookieHelper <ISessionHeaderInfo> .Clear(Constants.SecurityKey.HeaderInfo_SessionName, Constants.SecurityKey.HeaderInfo_CookieName);
            }
        }
Пример #4
0
        public async Task <IActionResult> HomeTaskPartial()
        {
            //Lấy người dùng hiện tại
            var user = await SessionCookieHelper.CurrentUser(this.HttpContext);

            //
            var data = await _WM_TaskService.GetTaskByUserId(user != null?user.UserId : "");

            return(PartialView(data));
        }
Пример #5
0
        private void SaveSessionHeaderInfoFromRoute(string channelId)
        {
            if (!string.IsNullOrEmpty(channelId))
            {
                if (SessionHeaderInfo == null)
                {
                    SessionHeaderInfo = new Model.Common.SessionHeaderInfo(Host);
                }
                SetSessionRouteChannelInfo(channelId);
            }

            SessionCookieHelper <ISessionHeaderInfo> .Save(SessionHeaderInfo, Constants.SecurityKey.HeaderInfo_SessionName, Constants.SecurityKey.HeaderInfo_CookieName, Constants.SecurityKey.key, Constants.SecurityKey.IV);
        }
Пример #6
0
        private void SaveSessionHeaderInfo(string channelId, string promotionCode)
        {
            if (!string.IsNullOrEmpty(channelId))
            {
                if (SessionHeaderInfo == null)
                {
                    SessionHeaderInfo = new Model.Common.SessionHeaderInfo(Host);
                }
                SessionHeaderInfo.ChannelId     = channelId;
                SessionHeaderInfo.PromotionCode = promotionCode;
            }

            SessionCookieHelper <ISessionHeaderInfo> .Save(SessionHeaderInfo, Constants.SecurityKey.HeaderInfo_SessionName, Constants.SecurityKey.HeaderInfo_CookieName, Constants.SecurityKey.key, Constants.SecurityKey.IV);
        }
Пример #7
0
        public async Task <IActionResult> HomeDiarySubmit(WM_Diary model)
        {
            var result = new MessageReport(false, "Có lỗi xảy ra");

            try
            {
                //Lấy người dùng hiện tại
                var currentUser = await SessionCookieHelper.CurrentUser(this.HttpContext);

                //Kiểm tra đã điền
                if (string.IsNullOrWhiteSpace(model.Title))
                {
                    result = new MessageReport(false, "Tên component không được để trống");
                    return(Json(result));
                }

                //Kiểm tra có tồn tại
                var existed = await _WM_DiaryService.GetById(model.Id);

                if (existed == null)
                {
                    //Thêm mới
                    existed = new WM_Diary()
                    {
                        DateCreated = DateTime.Now,
                        Description = model.Description,
                        Id          = model.Id,
                        Title       = model.Title,
                        ScheduleId  = model.ScheduleId,
                        UserId      = currentUser != null ? currentUser.UserId : ""
                    };

                    result = await _WM_DiaryService.Create(existed);
                }
                else
                {
                    //Cập nhật
                    existed.Title       = model.Title;
                    existed.Description = model.Description;

                    result = await _WM_DiaryService.Update(existed);
                }
            }
            catch (Exception ex)
            {
                result = new MessageReport(false, ex.Message);
            }

            return(Json(result));
        }
Пример #8
0
        public async Task <IActionResult> OneSignalrRegister(OneSignalrSubmit model)
        {
            var result = new MessageReport(false, "Có lỗi xảy ra");

            try
            {
                //Lấy người dùng hiện tại
                var user = await SessionCookieHelper.CurrentUser(this.HttpContext);

                if (user == null)
                {
                    result = new MessageReport(false, "Chưa đăng nhập");
                    return(Json(result));
                }

                if (string.IsNullOrWhiteSpace(model.PlayerId))
                {
                    result = new MessageReport(false, "Chưa có Player id");
                    return(Json(result));
                }

                //
                var existed = await _OS_PlayerService.GetByPlayerId_UserId(model.PlayerId, user.UserId);

                if (existed == null)
                {
                    existed = new Kztek_Model.Models.OneSignalr.OS_Player()
                    {
                        Id       = ObjectId.GenerateNewId().ToString(),
                        UserId   = user.UserId,
                        PlayerId = model.PlayerId
                    };

                    result = await _OS_PlayerService.Create(existed);
                }
                else
                {
                    result = new MessageReport(true, "Đã đăng ký");
                }
            }
            catch (Exception ex)
            {
                result = new MessageReport(false, ex.Message);
            }

            return(Json(result));
        }
Пример #9
0
        public async Task <IActionResult> HomePartial()
        {
            //Lấy người dùng hiện tại
            var user = await SessionCookieHelper.CurrentUser(this.HttpContext);

            //Lấy danh sách công việc của người đó trong các dự án chưa làm xong
            var dataWork = await _PM_WorkService.GetAllUnfinishedWorkByUserId(user.UserId);

            //Lấy danh sách dự án theo công việc đó
            var dataProject = await _PM_ProjectService.GetProjectsByIds(dataWork.Select(n => n.ProjectId).ToList());

            //Mapping
            var model = new PM_ProjectHomeModel()
            {
                Data_Project = dataProject
            };

            return(PartialView(model));
        }
Пример #10
0
        public async Task <IViewComponentResult> InvokeAsync(string controllername, string actionname)
        {
            //
            var user = await SessionCookieHelper.CurrentUser(HttpContextAccessor.HttpContext);

            var model = new SidebarModel();

            model.ControllerName = controllername;
            model.ActionName     = actionname;

            var data = await _SY_MenuFunctionService.GetAllActiveByUserId(HttpContextAccessor.HttpContext, user);

            model.Data = data.ToList();

            model.CurrentView = model.Data.FirstOrDefault(n => n.ControllerName.Equals(model.ControllerName) && n.ActionName.Equals(model.ActionName));

            model.Breadcrumb = await _SY_MenuFunctionService.GetBreadcrumb(model.CurrentView != null?model.CurrentView.Id : "", model.CurrentView != null?model.CurrentView.ParentId : "", "");

            return(View(model));
        }
Пример #11
0
        public async Task <IActionResult> HomeComponentPartial(string projectid)
        {
            //Lấy người dùng hiện tại
            var user = await SessionCookieHelper.CurrentUser(this.HttpContext);

            //Lấy dự án
            var objProject = await _PM_ProjectService.GetById(projectid);

            //Lấy danh sách công việc của người đó trong các dự án chưa làm xong
            var dataWork = await _PM_WorkService.GetAllUnfinishedWorkByUserId_ProjectId(user.UserId, projectid);

            //Lấy danh sách component theo wỏk
            var dataComponent = await _PM_ComponentService.GetAllCurrentByIds(dataWork.Select(n => n.ComponentId).ToList());

            ViewBag.UserIdValue     = user.UserId;
            ViewBag.projectidValue  = projectid;
            ViewBag.objProjectValue = objProject;

            return(PartialView(dataComponent));
        }
Пример #12
0
        public async Task <IActionResult> CreateNewProject(PM_Project model)
        {
            var result = new MessageReport(false, "Có lỗi xảy ra");

            try
            {
                if (string.IsNullOrWhiteSpace(model.Title))
                {
                    result = new MessageReport(false, "Vui lòng điền tên dự án");
                    return(Json(result));
                }

                //
                var currentUser = await SessionCookieHelper.CurrentUser(this.HttpContext);

                //Gán
                model.Id            = ObjectId.GenerateNewId().ToString();
                model.Description   = "";
                model.Note          = "";
                model.DateStart     = DateTime.Now;
                model.DateEnd       = DateTime.Now;
                model.DateCreated   = DateTime.Now;
                model.Status        = 0;
                model.UserCreatedId = currentUser != null ? currentUser.UserId : "";

                //
                result = await _PM_ProjectService.Create(model);

                if (result.isSuccess)
                {
                    result.Message = model.Id;
                }
            }
            catch (Exception ex)
            {
                result = new MessageReport(false, ex.Message);
            }

            return(Json(result));
        }
Пример #13
0
 public static ICurrentUser GetUser()
 {
     return(SessionCookieHelper <ICurrentUser> .Get(Constants.SecurityKey.LoginedUserInfo_SessionName, Constants.SecurityKey.LoginedUserInfo_CookieName, Constants.SecurityKey.key, Constants.SecurityKey.IV));
 }
Пример #14
0
 public static void ClearUser()
 {
     SessionCookieHelper <ICurrentUser> .Clear(Constants.SecurityKey.LoginedUserInfo_SessionName, Constants.SecurityKey.LoginedUserInfo_CookieName);
 }
Пример #15
0
 public static void SaveUser(ICurrentUser user)
 {
     SessionCookieHelper <ICurrentUser> .Save(user, Constants.SecurityKey.LoginedUserInfo_SessionName, Constants.SecurityKey.LoginedUserInfo_CookieName, Constants.SecurityKey.key, Constants.SecurityKey.IV);
 }
Пример #16
0
        public async Task <IActionResult> Create(WM_TaskSubmit model, bool SaveAndCountinue = false)
        {
            ViewBag.Select_User = await Select_User("");

            ViewBag.Select_Status = Select_ProjectStatus(model.Status.ToString());
            var users = new string[] { };

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var currentUser = await SessionCookieHelper.CurrentUser(this.HttpContext);

            var obj = new WM_Task()
            {
                DateCreated   = DateTime.Now,
                DateEnd       = Convert.ToDateTime(model.DateEnd),
                DateStart     = Convert.ToDateTime(model.DateStart),
                Description   = model.Description,
                Id            = ObjectId.GenerateNewId().ToString(),
                Title         = model.Title,
                Status        = 0,
                Note          = "",
                UserCreatedId = currentUser != null ? currentUser.UserId : ""
            };

            if (model.UserIds.Any())
            {
                //Lấy danh sách mới
                //users = model.UserIds.Split(',', StringSplitOptions.RemoveEmptyEntries);
                foreach (var item in model.UserIds)
                {
                    var userTask = new WM_TaskUser()
                    {
                        Id            = ObjectId.GenerateNewId().ToString(),
                        TaskId        = obj.Id,
                        UserId        = item,
                        IsCompleted   = false,
                        IsOnScheduled = false,
                        DateCompleted = DateTime.Now,
                        DateCreated   = DateTime.Now
                    };

                    await _WM_TaskService.CreateUserTask(userTask);
                }

                //Thêm người tạo dự án
                users.Append(obj.UserCreatedId);
            }

            //Thực hiện thêm mới
            var result = await _WM_TaskService.Create(obj);

            if (result.isSuccess)
            {
                SendMessage(obj, users.ToList());

                RegisterSchedule(obj);

                //Lưu lại log trên server
                _SY_ReminderSystemService.Create(new Kztek_Model.Models.SY_ReminderSystem()
                {
                    Id           = obj.Id,
                    Type         = "task",
                    isDone       = false,
                    DateReminder = obj.DateEnd.AddMinutes(-15)
                });

                if (SaveAndCountinue)
                {
                    TempData["Success"] = "Thêm mới thành công";
                    return(RedirectToAction("Create"));
                }

                return(RedirectToAction("Index"));
            }
            else
            {
                ModelState.AddModelError("", result.Message);
                return(View(obj));
            }
        }
Пример #17
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var user = await SessionCookieHelper.CurrentUser(HttpContext);

            return(View(user));
        }
        public async Task <IViewComponentResult> InvokeAsync(string controllername, string actionname)
        {
            //
            var user = await SessionCookieHelper.CurrentUser(HttpContextAccessor.HttpContext);

            //
            var model = new BreadcrumbModel();

            model.ControllerName = controllername;
            model.ActionName     = actionname;

            var data = await _SY_MenuFunctionService.GetAllActiveByUserId(HttpContextAccessor.HttpContext, user);

            var dataList = data.ToList();

            model.CurrentView = dataList.FirstOrDefault(n => n.ControllerName.Equals(model.ControllerName) && n.ActionName.Equals(model.ActionName));

            var k = await LanguageHelper.GetMenuLanguageText(string.Format("{0}:{1}", controllername, actionname));

            if (!string.IsNullOrWhiteSpace(k))
            {
                if (model.CurrentView != null)
                {
                    model.CurrentView.MenuName = k;
                }
            }

            model.Breadcrumb = await _SY_MenuFunctionService.GetBreadcrumb(model.CurrentView != null?model.CurrentView.Id : "", model.CurrentView != null?model.CurrentView.ParentId : "", "");

            //List
            var listModel = new List <SelectListModel_Breadcrumb>();


            if (!string.IsNullOrWhiteSpace(model.Breadcrumb))
            {
                var id = model.Breadcrumb.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                if (id.Any())
                {
                    foreach (var item in id.Reverse())
                    {
                        var objF = dataList.FirstOrDefault(n => n.Id.Equals(item));
                        if (objF != null)
                        {
                            var childFunc = dataList.Where(n => n.ParentId == objF.Id && n.MenuType == "2");

                            if (!listModel.Any(n => n.ControllerName == objF.ControllerName && n.ActionName == objF.ActionName))
                            {
                                if (model.CurrentView != null)
                                {
                                    if (model.CurrentView.ControllerName == objF.ControllerName && model.CurrentView.ActionName == objF.ActionName)
                                    {
                                    }
                                    else
                                    {
                                        var menuname = await LanguageHelper.GetMenuLanguageText(string.Format("{0}:{1}", objF.ControllerName, objF.ActionName));

                                        listModel.Add(new SelectListModel_Breadcrumb
                                        {
                                            MenuName       = objF.MenuName,
                                            ControllerName = objF.ControllerName,
                                            ActionName     = objF.ActionName,
                                            isFolder       = childFunc.Any() ? false : true
                                        });
                                    }
                                }
                                else
                                {
                                    var menuname = await LanguageHelper.GetMenuLanguageText(string.Format("{0}:{1}", objF.ControllerName, objF.ActionName));

                                    listModel.Add(new SelectListModel_Breadcrumb
                                    {
                                        MenuName       = objF.MenuName,
                                        ControllerName = objF.ControllerName,
                                        ActionName     = objF.ActionName,
                                        isFolder       = childFunc.Any() ? false : true
                                    });
                                }
                            }
                        }
                    }
                }
            }

            model.Data = listModel;

            return(View(model));
        }
Пример #19
0
        // public IActionResult Export()
        // {
        //     ();
        //     return Json("");

        //     // return File(
        //     //     fileContents: data,
        //     //     contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
        //     //     fileDownloadName: excelName
        //     // );

        //     //return File(memory, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", excelName);
        // }

        private async Task <bool> ExportFile(HttpContext context)
        {
            //column header
            var Data_ColumnHeader = new List <SelectListModel_Print_Column_Header>();

            Data_ColumnHeader.Add(new SelectListModel_Print_Column_Header {
                ItemText = "ID"
            });
            Data_ColumnHeader.Add(new SelectListModel_Print_Column_Header {
                ItemText = "Họ tên"
            });
            Data_ColumnHeader.Add(new SelectListModel_Print_Column_Header {
                ItemText = "Tài khoản"
            });
            Data_ColumnHeader.Add(new SelectListModel_Print_Column_Header {
                ItemText = "MK"
            });
            Data_ColumnHeader.Add(new SelectListModel_Print_Column_Header {
                ItemText = "MKSA"
            });
            Data_ColumnHeader.Add(new SelectListModel_Print_Column_Header {
                ItemText = "Là admin"
            });
            Data_ColumnHeader.Add(new SelectListModel_Print_Column_Header {
                ItemText = "Hoạt động"
            });
            Data_ColumnHeader.Add(new SelectListModel_Print_Column_Header {
                ItemText = "Ảnh"
            });

            //
            var printConfig = PrintHelper.Template_Excel_V1(PrintConfig.HeaderType.TwoColumns, "Danh sách người dùng", DateTime.Now, SessionCookieHelper.CurrentUser(this.HttpContext).Result, "Kztek", Data_ColumnHeader, 4, 5, 5);

            //
            var gridmodel = await _SY_UserService.GetPaging("", 1, 10);

            return(await PrintHelper.Excel_Write <SY_User>(context, gridmodel.Data, "User_" + DateTime.Now.ToString("ddMMyyyyHHmmss"), printConfig));
        }
Пример #20
0
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            var connecttype = AppSettingHelper.GetStringFromFileJson("connectstring", "ConnectionStrings:DefaultType").Result;

            //Check có session / cookie
            var currentUser = SessionCookieHelper.CurrentUser(HttpContextAccessor.HttpContext).Result;

            if (currentUser == null)
            {
                context.Result = new RedirectResult("/Login/Index");
                return;
            }

            switch (connecttype)
            {
            case DatabaseModel.MONGO:

                var filter = Builders <SY_User> .Filter.Eq(n => n.Id, currentUser.UserId);

                var kd = MongoHelper.GetConnect <SY_User>().FindAsync(filter).Result.FirstOrDefault();

                if (kd == null)
                {
                    context.Result = new RedirectResult("/Login/Index");
                    return;
                }

                break;

            default:

                //Check tk tồn tại trong db
                var cmdq = string.Format("SELECT * FROM sy_user WHERE Id = '{0}'", currentUser.UserId);

                var result = Kztek_Library.Helpers.DatabaseHelper.ExcuteCommandToBool(cmdq);

                if (result == false)
                {
                    context.Result = new RedirectResult("/Login/Index");
                    return;
                }

                break;
            }

            //Check quyền
            if (currentUser.isAdmin == false)
            {
                //Id menu hiện tại
                var controller = (string)context.RouteData.Values["Controller"];
                var action     = (string)context.RouteData.Values["Action"];

                var modelCache = AuthHelper.MenuFunctionByUserId(currentUser, HttpContextAccessor.HttpContext).Result;

                if (!modelCache.Any(n => n.ControllerName == controller && n.ActionName == action))
                {
                    context.Result = new RedirectResult("/Home/NotAuthorize");
                    return;
                }
            }
        }