コード例 #1
0
        ////insert dữ liệu

        //[HttpPost]
        //public JsonResult insert([FromBody]edu_course obj)
        //{
        //    var msg = new JMessage() { Error = false };
        //    try
        //    {
        //        var query = from a in _context.edu_course
        //                    where a.course_code == obj.course_code
        //                    select a;
        //        if(query.Count() == 0)
        //        {
        //            edu_course obj1 = new edu_course();
        //            obj1.course_code = obj.course_code;
        //            obj1.course_name = obj.course_name;
        //            obj1.coursetype = obj.coursetype;
        //            //   obj1.Birthday = Convert.ToDateTime(obj.Birthday);
        //            obj1.note = obj.note;
        //            obj1.price = obj.price;
        //            obj1.totalday = obj.totalday;
        //            obj1.userid = obj.userid;
        //            obj1.level = obj.level;
        //            obj1.flag = 1;
        //            obj1.createtime = DateTime.Now;

        //            _context.edu_course.Add(obj1);
        //            _context.SaveChanges();
        //            msg.Title = "Thêm thành công";
        //        }
        //        else
        //        {
        //            msg.Error = true;
        //            msg.Title = "Mã đã tồn tại";
        //        }

        //    }
        //    catch (Exception ex)
        //    {
        //        msg.Error = true;
        //        msg.Object = ex;
        //        msg.Title = "Có lỗi khi thêm ";
        //    }
        //    return Json(msg);
        //}

        ////update dữ liệu
        //[HttpPost]
        //public JsonResult update([FromBody]edu_course obj)
        //{
        //    var msg = new JMessage() { Error = true };
        //    try
        //    {
        //        var rs = _context.edu_course.SingleOrDefault(x => x.id == obj.id);
        //        if (rs != null)
        //        {
        //            rs.id = obj.id;
        //            rs.course_name = obj.course_name;
        //            rs.note = obj.note;
        //            rs.coursetype = obj.coursetype;
        //            rs.updatetime = DateTime.Now;
        //            rs.price = obj.price;
        //            rs.userid = obj.userid;

        //            rs.course_code = obj.course_code;

        //            rs.totalday = obj.totalday;
        //            rs.level = obj.level;


        //            _context.edu_course.Update(rs);

        //            _context.SaveChanges();
        //            msg.Title = "Cập nhật thông tin thành công";
        //            msg.Error = false;

        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        msg.Object = ex;
        //        msg.Title = "Có lỗi khi cập nhật";

        //    }
        //    return Json(msg);
        //}



        public async Task <JsonResult> Insert(edu_cat_ranking obj, IFormFile picture)
        {
            var msg = new JMessage()
            {
                Error = false, ID = 1
            };

            try
            {
                var icpicture = "";

                if (picture != null && picture.Length > 0)
                {
                    var pathUpload = Path.Combine(_hostingEnvironment.WebRootPath, "pictures\\avatar");
                    if (!Directory.Exists(pathUpload))
                    {
                        Directory.CreateDirectory(pathUpload);
                    }

                    var fileName = DateTimeOffset.Now.ToUnixTimeMilliseconds() + picture.FileName;
                    var filePath = Path.Combine(pathUpload, fileName);
                    using (var stream = new FileStream(filePath, FileMode.Create))
                    {
                        await picture.CopyToAsync(stream);
                    }
                    icpicture = "/pictures/avatar/" + fileName;
                }
                if (icpicture != "")
                {
                    obj.picture = icpicture;
                }


                obj.createtime = DateTime.Now;
                obj.flag       = 1;
                _context.edu_cat_ranking.Add(obj);
                _context.SaveChanges();

                msg.Title = "Thêm mới xếp hạng thành công";
                msg.Error = false;
                _actionLog.InsertActionLog("edu_cat_ranking", "Insert new edu_cat_ranking successfully", null, obj, "Insert");
            }
            catch (Exception ex)
            {
                msg.ID     = 0;
                msg.Error  = true;
                msg.Object = ex;
                msg.Title  = "Có lỗi khi thêm khoản mục";
                _actionLog.InsertActionLog("edu_cat_ranking", "Insert new edu_cat_ranking fail", null, obj, "Insert");
            }
            return(Json(msg));
        }
コード例 #2
0
        public JsonResult Insert([FromBody] AdOrganization obj)
        {
            //_logger.LogInformation(LoggingEvents.LogDb, "Insert Organization");
            var msg = new JMessage()
            {
                Error = false
            };

            try
            {
                var org = _context.AdOrganizations.Where(x => x.OrgCode.Equals(obj.OrgCode)).FirstOrDefault();
                //var org = _context.AdOrganizations.Where(x => int.Parse(x.OrgCode).Equals(int.Parse(obj.OrgCode))).FirstOrDefault();
                if (org == null)
                {
                    var adOrganizations = new AdOrganization
                    {
                        Division      = int.Parse(obj.Division) > 0 ? obj.Division : string.Concat("0", obj.Division),
                        OrgCode       = obj.OrgCode,
                        OrgName       = obj.OrgName,
                        OrgAddonCode  = "b_" + obj.OrgCode,
                        OrgGroup      = 2,
                        OrgUpdateTime = DateTime.Now.ToString(),
                        Company       = "BRA",
                        Country       = "VN",
                        State         = "01",
                        HierarchyCode = "11",
                        IsEnabled     = true,
                        OrgId         = _context.AdOrganizations.Max(x => x.OrgId) + 1
                    };

                    //msg.Title = "Thêm Chi nhánh thành công !";
                    msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_ADD_SUCCESS"), CommonUtil.ResourceValue("ADM_BRANCH_LBL_BRANCH").ToLower());
                    _context.AdOrganizations.Add(adOrganizations);
                    _context.SaveChanges();
                    //_logger.LogInformation(LoggingEvents.LogDb, "Insert Organization Success");
                    _actionLog.InsertActionLog("AdOrganization", "Insert Organization Success", null, obj, "Insert");
                }
                else
                {
                    msg.Error = true;
                    //msg.Title = "Chi nhánh đã tồn tại!";
                    msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_EXITS"), CommonUtil.ResourceValue("ADM_BRANCH_LBL_BRANCH"));
                }
            }
            catch (Exception ex)
            {
                msg.Error = true;
                //msg.Title = "Thêm Chi nhánh thất bại !";
                msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_ADD_FAILED"), CommonUtil.ResourceValue("ADM_BRANCH_LBL_BRANCH"));
                //_logger.LogError(LoggingEvents.LogDb, "Insert Organization Fail");
                _actionLog.InsertActionLog("AdOrganization", "Insert Organization Fail", null, null, "Error");
            }
            return(Json(msg));
        }
コード例 #3
0
ファイル: UI2Controller.cs プロジェクト: war-man/alpha_net
        public async Task <JsonResult> Insert(Jnana_news_cat obj, IFormFile cat_avarta)
        {
            var msg = new JMessage()
            {
                Error = false, ID = 1
            };

            try
            {
                Jnana_news_cat rs = _context.Jnana_news_cat.FirstOrDefault(x => x.cat_code == obj.cat_code);
                if (rs == null)
                {
                    var iccat_avarta = "";

                    if (cat_avarta != null && cat_avarta.Length > 0)
                    {
                        var pathUpload = Path.Combine(_hostingEnvironment.WebRootPath, "cat_avartas\\avatar");
                        if (!Directory.Exists(pathUpload))
                        {
                            Directory.CreateDirectory(pathUpload);
                        }

                        var fileName = DateTimeOffset.Now.ToUnixTimeMilliseconds() + cat_avarta.FileName;
                        var filePath = Path.Combine(pathUpload, fileName);
                        using (var stream = new FileStream(filePath, FileMode.Create))
                        {
                            await cat_avarta.CopyToAsync(stream);
                        }
                        iccat_avarta = "/cat_avartas/avatar/" + fileName;
                    }
                    if (iccat_avarta != "")
                    {
                        obj.cat_avarta = iccat_avarta;
                    }


                    obj.created_time = DateTime.Now;
                    obj.cat_status   = 1;
                    _context.Jnana_news_cat.Add(obj);
                    _context.SaveChanges();

                    msg.Title = "Thêm mới danh mục thành công";
                    msg.Error = false;
                    _actionLog.InsertActionLog("Jnana_news_cat", "Insert new category successfully", null, obj, "Insert");
                }
                else
                {
                    msg.Title = "Mã đã tồn tại";
                    msg.Error = true;
                }
            }
            catch (Exception ex)
            {
                msg.ID     = 0;
                msg.Error  = true;
                msg.Object = ex;
                msg.Title  = "Có lỗi khi thêm khoản mục";
                _actionLog.InsertActionLog("news_category", "Insert new category fail", null, obj, "Insert");
            }
            return(Json(msg));
        }
コード例 #4
0
        public async Task <JsonResult> Insert(AdApplication obj, IFormFile uploadIcon)
        {
            //_logger.LogInformation(LoggingEvents.LogDb, "Insert application");
            var msg = new JMessage()
            {
                Error = false
            };

            try
            {
                var app = _context.AdApplications.FirstOrDefault(x => x.ApplicationCode == obj.ApplicationCode);
                if (app == null)
                {
                    var iconUrl = string.Empty;
                    if (uploadIcon != null && uploadIcon.Length > 0)
                    {
                        var pathUpload = Path.Combine(_hostingEnvironment.WebRootPath, "images\\appIcon");
                        if (!Directory.Exists(pathUpload))
                        {
                            Directory.CreateDirectory(pathUpload);
                        }

                        var fileName = obj.ApplicationCode + "-" + uploadIcon.FileName;
                        var filePath = Path.Combine(pathUpload, fileName);
                        using (var stream = new FileStream(filePath, FileMode.Create))
                        {
                            await uploadIcon.CopyToAsync(stream);
                        }
                        iconUrl  = "/images/appIcon/" + fileName;
                        obj.Icon = iconUrl;
                    }
                    obj.Status = 1;
                    _context.AdApplications.Add(obj);
                    var a = _context.SaveChanges();
                    msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_ADD_SUCCESS"), CommonUtil.ResourceValue("ADM_APP_LBL_APP")); //"Thêm khoản mục thành công";
                    //_logger.LogInformation(LoggingEvents.LogDb, "Insert application successfully");
                    _actionLog.InsertActionLog("VIB_APPLICATION", "Insert application successfully", null, obj, "Insert");
                }
                else
                {
                    msg.Error = true;
                    msg.Title = String.Format(CommonUtil.ResourceValue("COM_ERR_EXIST"), CommonUtil.ResourceValue("APP_CODE"));
                    //_logger.LogError(LoggingEvents.LogDb, "Insert application fail");
                    _actionLog.InsertActionLog("VIB_APPLICATION", "Insert application fail: Application code is exists", null, null, "Error");

                    return(Json(msg));
                }
            }
            catch (Exception ex)
            {
                msg.Error = true;
                msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_ADD_FAIL"), CommonUtil.ResourceValue("ADM_APP_LBL_APP")); //"Có lỗi khi thêm khoản mục";
                //_logger.LogError(LoggingEvents.LogDb, "Insert application fail");
                _actionLog.InsertActionLog("VIB_APPLICATION", "Insert application failed: " + ex.Message, null, null, "Error");
            }
            return(Json(msg));
        }
コード例 #5
0
        public async Task <JsonResult> UpdatePermission([FromBody] PermissionModel model)
        {
            JMessage msg = new JMessage {
                Error = true, Title = string.Format(CommonUtil.ResourceValue("MSG_UPDATE_FAIL"), CommonUtil.ResourceValue("PERMISSION").ToLower())
            };

            try
            {
                model.Resources = model.Resources.Where(x => !x.IsFunction).ToList();
                if (model.GroupCodes.Count > 0)
                {
                    var listFunctionChild = await _context.AdFunctions.Where(x => x.FunctionCode == model.FunctionCode || x.ParentCode == model.FunctionCode || x.Parent.ParentCode == model.FunctionCode).ToListAsync();

                    var listGroupUser = await _context.AdGroupUsers.Where(x => model.GroupCodes.Any(y => y == x.GroupUserCode)).ToListAsync();

                    var listUserInGroup = await _context.AdUserInGroups.Where(x => model.GroupCodes.Any(y => y == x.GroupUserCode) && x.RoleId == model.RoleId).ToListAsync();

                    var listPermissionAll = await _context.AdPermissions.Where(x => x.ApplicationCode == model.ApplicationCode && x.RoleId == model.RoleId && listGroupUser.Any(y => y.GroupUserCode == x.GroupUserCode) && (string.IsNullOrEmpty(model.FunctionCode) || listFunctionChild.Any(y => y.FunctionCode == x.FunctionCode))).ToListAsync();

                    var listPermissionDefault = listPermissionAll.Where(x => x.UserId == null).ToList();
                    var listPermissionUser    = listPermissionAll.Where(x => x.UserId != null).ToList();
                    if (listGroupUser.Count > 0)
                    {
                        foreach (var groupUser in listGroupUser)
                        {
                            if (!model.IsMultiple)
                            {
                                // Remove permission default
                                var delPermissionDefault = listPermissionDefault.Where(x => x.GroupUserCode == groupUser.GroupUserCode && !model.Resources.Any(y => y.HasPermission && !y.IsFunction && y.FunctionCode == x.FunctionCode && y.Code == x.ResourceCode));
                                _context.RemoveRange(delPermissionDefault);

                                // Remove permission user
                                var delPermissionUser = listPermissionUser.Where(x => x.GroupUserCode == groupUser.GroupUserCode && !model.Resources.Any(y => y.HasPermission && !y.IsFunction && y.FunctionCode == x.FunctionCode && y.Code == x.ResourceCode));
                                _context.RemoveRange(delPermissionUser);
                            }

                            // Add permission default
                            var addPermissionDefault = model.Resources.Where(x => x.HasPermission && !x.IsFunction && !listPermissionDefault.Any(y => y.GroupUserCode == groupUser.GroupUserCode && y.FunctionCode == x.FunctionCode && y.ResourceCode == x.Code))
                                                       .Select(x => new AdPermission
                            {
                                ApplicationCode = model.ApplicationCode,
                                FunctionCode    = x.FunctionCode,
                                ResourceCode    = x.Code,
                                GroupUserCode   = groupUser.GroupUserCode,
                                RoleId          = model.RoleId,
                                UserId          = null,
                            });
                            _context.AddRange(addPermissionDefault);

                            // Add permission user
                            var listUser = listUserInGroup.Where(x => x.GroupUserCode == groupUser.GroupUserCode).ToList();
                            //var permissionUser = listPermissionUser.Where(x => x.GroupUserCode == groupUser.GroupUserCode).GroupBy(g => g.UserId).ToList();
                            if (listUser.Count > 0)
                            {
                                foreach (var perUser in listUser)
                                {
                                    var addPermissionUser = model.Resources.Where(x => x.HasPermission && !x.IsFunction && x.Scope == false && !listPermissionUser.Any(y => y.GroupUserCode == groupUser.GroupUserCode && y.FunctionCode == x.FunctionCode && y.ResourceCode == x.Code))
                                                            .Select(x => new AdPermission
                                    {
                                        ApplicationCode = model.ApplicationCode,
                                        FunctionCode    = x.FunctionCode,
                                        ResourceCode    = x.Code,
                                        GroupUserCode   = groupUser.GroupUserCode,
                                        RoleId          = model.RoleId,
                                        UserId          = perUser.UserId,
                                    });
                                    _context.AddRange(addPermissionUser);
                                }
                            }
                        }
                    }

                    var result = await _context.SaveChangesAsync();
                }
                _actionLog.InsertActionLog("VIB_PERMISSION", "Update define permission for deparment/profit center success", null, null, "Update");

                msg.Error = false;
                msg.Title = string.Format(CommonUtil.ResourceValue("MSG_UPDATE_SUCCESS"), CommonUtil.ResourceValue("PERMISSION").ToLower());
            }
            catch (Exception ex)
            {
                _actionLog.InsertActionLog("VIB_PERMISSION", "Update define permission failed: " + ex.Message, null, null, "Error");
                msg.Object = ex;
            }

            return(Json(msg));
        }
コード例 #6
0
        public async Task <JsonResult> Insert([FromBody] AspNetRole obj)
        {
            var msg = new JMessage()
            {
                Error = false
            };

            try
            {
                var role = _context.Roles.FirstOrDefault(x => x.Code == obj.Code);
                if (role == null)
                {
                    var r = _context.Roles.FirstOrDefault(x => x.Title == obj.Title || x.Name == obj.Title);
                    if (r == null)
                    {
                        role                = new AspNetRole();
                        role.Name           = obj.Code;
                        role.NormalizedName = obj.Code.ToUpper();
                        role.Code           = obj.Code;
                        role.Title          = obj.Title;
                        role.Status         = obj.Status;
                        role.Description    = obj.Description;
                        role.CreatedDate    = DateTime.Now;
                        role.CreatedBy      = User.Identity.Name;

                        await _roleManager.CreateAsync(role);

                        msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_ADD_SUCCESS"), CommonUtil.ResourceValue("ADM_ROLE_LBL_ROLE").ToLower());
                        ////_logger.LogInformation(LoggingEvents.LogDb, "Insert role successfully");
                        _actionLog.InsertActionLog("ASP_NET_ROLES", "Insert role successfully", null, obj, "Insert");
                    }
                    else
                    {
                        msg.Error = true;
                        msg.Title = String.Format(CommonUtil.ResourceValue("COM_ERR_EXIST"), CommonUtil.ResourceValue("ADM_ROLE_CURD_LBL_ROLE_CODE"));
                        //_logger.LogError(LoggingEvents.LogDb, "Insert role fail");
                        _actionLog.InsertActionLog("ASP_NET_ROLES", "Insert role failed: Role name is exists", null, null, "Error");
                    }
                }
                else
                {
                    msg.Error = true;
                    msg.Title = String.Format(CommonUtil.ResourceValue("COM_ERR_EXIST"), CommonUtil.ResourceValue("ADM_ROLE_CURD_LBL_ROLE_CODE"));
                    //_logger.LogError(LoggingEvents.LogDb, "Insert role fail");
                    _actionLog.InsertActionLog("ASP_NET_ROLES", "Insert role failed: Role code is exists", null, null, "Error");
                }
            }
            catch (Exception ex)
            {
                msg.Error = true;
                msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_ADD_FAIL"), CommonUtil.ResourceValue("ADM_ROLE_LBL_ROLE").ToLower());
                //_logger.LogError(LoggingEvents.LogDb, "Insert role fail");
                _actionLog.InsertActionLog("ASP_NET_ROLES", "Insert role failed: " + ex.Message, null, null, "Error");
            }
            return(Json(msg));
        }
コード例 #7
0
        public async Task <IActionResult> UpdatePermission([FromBody] PermissionModel model)
        {
            JMessage msg = new JMessage {
                Error = true, Title = string.Format(CommonUtil.ResourceValue("MSG_UPDATE_FAIL"), CommonUtil.ResourceValue("PERMISSION").ToLower())
            };

            try
            {
                if (model.UserInGroups.Count > 0 && model.Resources.Count > 0)
                {
                    foreach (var user in model.UserInGroups)
                    {
                        foreach (var resource in model.Resources)
                        {
                            var permission = await _context.AdPermissions.FirstOrDefaultAsync(x => x.ApplicationCode == model.ApplicationCode && x.FunctionCode == resource.FunctionCode && x.ResourceCode == resource.Code && x.GroupUserCode == user.GroupUserCode && x.UserId == user.UserId);

                            if (permission == null)
                            {
                                if (resource.HasPermission)
                                {
                                    // Add new permission
                                    permission = new AdPermission();
                                    permission.ApplicationCode = model.ApplicationCode;
                                    permission.FunctionCode    = resource.FunctionCode;
                                    permission.ResourceCode    = resource.Code;
                                    permission.GroupUserCode   = user.GroupUserCode;
                                    permission.UserId          = user.UserId;
                                    permission.RoleId          = user.RoleId;
                                    _context.AdPermissions.Add(permission);
                                    _actionLog.InsertActionLog("VIB_PERMISSION", "Add permission successfully", null, permission, "Insert");
                                }
                            }
                            else
                            {
                                if (resource.HasPermission)
                                {
                                    // Update permission
                                    permission.RoleId = user.RoleId;
                                    _context.AdPermissions.Update(permission);
                                    _actionLog.InsertActionLog("VIB_PERMISSION", "Update permission successfully", null, permission, "Insert");
                                }
                                else
                                {
                                    _context.AdPermissions.Remove(permission);
                                    await _context.SaveChangesAsync();
                                }
                            }
                        }
                        // Update role of user in group
                        var userInGroup = await _context.AdUserInGroups.FirstOrDefaultAsync(x => x.GroupUserCode == user.GroupUserCode && x.UserId == user.UserId);

                        if (userInGroup != null)
                        {
                            userInGroup.RoleId = user.RoleId;
                            _context.AdUserInGroups.Update(userInGroup);
                        }
                    }

                    var result = await _context.SaveChangesAsync();

                    //if (result > 0)
                    //{
                    //_logger.LogInformation(LoggingEvents.LogDb, "Update permission success");
                    //_actionLog.InsertActionLog("VIBGroupUser", "Update permission success", objOld, model, "Update");

                    //}
                }

                msg.Error = false;
                msg.Title = string.Format(CommonUtil.ResourceValue("MSG_UPDATE_SUCCESS"), CommonUtil.ResourceValue("PERMISSION").ToLower());
                //_actionLog.InsertActionLog("VIBPermissionResoure", "MSG_UPDATE_SUCCESS", null, model, "Insert");
            }
            catch (Exception ex)
            {
                //_logger.LogError(LoggingEvents.LogDb, "Update permission failed");
                _actionLog.InsertActionLog("VIB_PERMISSION", "Update permission failed", null, null, "Error");

                msg.Object = ex;
            }

            return(Json(msg));
        }