Exemplo n.º 1
0
        public async Task <ActionResult> Update(UserModelDetail model)
        {
            if (!model.Groups.Any(n => n.IsCheck == true))
            {
                AlertWarning("Người dùng này chưa thuộc nhóm người dùng nào cả, hãy chọn nhóm của người dùng.");
                return(View(model));
            }

            if (ModelState.IsValid)
            {
                _groupService.BeginTran();
                try
                {
                    var userFindByEmail = await _userManager.FindByEmailAsync(model.User.Email);

                    if (userFindByEmail != null && !userFindByEmail.Id.Equals(model.User.Id))
                    {
                        AlertWarning(InfoString.SetContainString("Email"));
                        return(View(model));
                    }
                    var userNeedUpdate = await _userManager.FindByIdAsync(model.User.Id);

                    userNeedUpdate.FullName   = model.User.FullName;
                    userNeedUpdate.Email      = model.User.Email;
                    userNeedUpdate.BirthDay   = model.User.BirthDay;
                    userNeedUpdate.Status     = model.User.Status;
                    userNeedUpdate.UpdateBy   = GetCurrentInstance().UserName;
                    userNeedUpdate.UpdateDate = DateTime.Now;
                    var result = await _userManager.UpdateAsync(userNeedUpdate);

                    if (result.Succeeded)
                    {
                        //delete oder group of user
                        _groupService.DeleteGroupOfUser(model.User.Id);
                        _groupService.CommitChanges();

                        //add user to new groups
                        foreach (var item in model.Groups)
                        {
                            if (item.IsCheck)
                            {
                                _groupService.AddUserToGroup(model.User.Id, item.Id);
                            }
                        }
                        _groupService.CommitChanges();
                        _groupService.CommitTran();
                        AlertSuccess(InfoString.UPDATE_SUCCESSFULL);
                    }
                }
                catch (Exception ex)
                {
                    Log(ex);
                    AlertError(InfoString.ERROR_SYSTEM);
                    _groupService.RollbackTran();
                }
                return(RedirectToAction("Index"));
            }
            AlertWarning(InfoString.INVALID_INFO);
            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult Update(Role model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var check = _roleService.CheckContain(model.Id, model.Name);
                    if (check)
                    {
                        AlertWarning(InfoString.SetContainString("Tên quyền"));
                        return(View(model));
                    }

                    model.UpdateDate = DateTime.Now;
                    model.UpdateBy   = GetCurrentInstance().UserName;
                    _roleService.Update(model);
                    _roleService.CommitChanges();
                    AlertSuccess(InfoString.UPDATE_SUCCESSFULL);
                }
                catch (Exception ex)
                {
                    Log(ex);
                    AlertError(InfoString.ERROR_SYSTEM);
                }
                return(RedirectToAction("Index"));
            }
            AlertWarning(InfoString.INVALID_INFO);
            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult CreateNew(Category model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var flagCode = _categoryService.CheckContain(model.Code);
                    if (flagCode)
                    {
                        AlertWarning(InfoString.SetContainString("Mã danh mục"));
                        ViewData["CategoryTypes"]   = COMMON.Helper.TypeCategory.GetTypes();
                        ViewData["CategoryParents"] = _categoryService.GetParents(model.Type);
                        return(View(model));
                    }
                    model.CreateBy   = GetCurrentInstance().UserName;
                    model.CreateDate = DateTime.Now;
                    _categoryService.CreateNew(model);
                    _categoryService.CommitChanges();
                    AlertSuccess(InfoString.CREATE_SUCCESSFULL);
                }
                catch (Exception ex)
                {
                    Log(ex);
                    AlertError(InfoString.ERROR_SYSTEM);
                }

                return(RedirectToAction("Index", "Category", new { ParentId = model.ParentId, TypeId = model.Type }));
            }
            AlertWarning(InfoString.INVALID_INFO);
            ViewData["CategoryTypes"]   = COMMON.Helper.TypeCategory.GetTypes();
            ViewData["CategoryParents"] = _categoryService.GetParents(model.Type);
            return(View(model));
        }
        public ActionResult Update(Design model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var flag = _designService.CheckContain(model.Id, model.Name);
                    if (flag)
                    {
                        AlertWarning(InfoString.SetContainString("Tên"));
                        ViewData["ParentCategories"] = _categoryService.GetParents(1);//parent type production
                        return(View(model));
                    }

                    model.UpdateBy   = "hadacduong";
                    model.UpdateDate = DateTime.Now;
                    _designService.Update(model);
                    _designService.CommitChanges();
                    AlertSuccess(InfoString.UPDATE_SUCCESSFULL);
                }
                catch (Exception ex)
                {
                    Log(ex);
                    AlertError(InfoString.ERROR_SYSTEM);
                }

                return(RedirectToAction("Index", "Design", new { ParentCategoryId = model.ParentCategoryId }));
            }
            AlertWarning(InfoString.INVALID_INFO);
            ViewData["ParentCategories"] = _categoryService.GetParents(1);//parent type production
            return(View(model));
        }
Exemplo n.º 5
0
        public ActionResult Update(Meterial model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var flag = _meTerialService.CheckContain(model.Id, model.Name);
                    if (flag)
                    {
                        AlertWarning(InfoString.SetContainString("Tên"));
                        return(View(model));
                    }

                    model.UpdateDate = DateTime.Now;
                    model.UpdateBy   = "hadacduong";
                    _meTerialService.Update(model);
                    _meTerialService.CommitChanges();
                    AlertSuccess(InfoString.UPDATE_SUCCESSFULL);
                }
                catch (Exception ex)
                {
                    Log(ex);
                    AlertError(InfoString.ERROR_SYSTEM);
                }

                return(RedirectToAction("Index"));
            }
            AlertWarning(InfoString.INVALID_INFO);
            return(View(model));
        }
Exemplo n.º 6
0
        public ActionResult Update(Size model)
        {
            try
            {
                bool check = _sizeService.CheckContain(model.Id, model.Width, model.Height, model.Unit);
                if (check)
                {
                    AlertWarning(InfoString.SetContainString("Kích thước"));
                    ViewData["UnitOfSize"] = UnitOfSizeCategory.GetUnitsOfSize();
                    return(View(model));
                }

                model.UpdateBy   = "hadacduong";
                model.UpdateDate = DateTime.Now;
                _sizeService.Update(model);
                _sizeService.CommitChanges();
                AlertSuccess(InfoString.UPDATE_SUCCESSFULL);
            }
            catch (Exception ex)
            {
                Log(ex);
                AlertError(InfoString.ERROR_SYSTEM);
            }

            return(RedirectToAction("Index"));
        }
Exemplo n.º 7
0
        public async Task <ActionResult> CreateNew(UserModelDetail model)
        {
            if (!model.Groups.Any(n => n.IsCheck == true))
            {
                AlertWarning("Người dùng này chưa thuộc nhóm người dùng nào cả, hãy chọn nhóm của người dùng.");
                return(View(model));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var checkUser = await _userManager.FindByNameAsync(model.User.UserName);

                    if (checkUser != null)
                    {
                        AlertWarning(InfoString.SetContainString("Tên đăng nhập"));
                        return(View(model));
                    }

                    var userByEmail = await _userManager.FindByEmailAsync(model.User.Email);

                    if (userByEmail != null)
                    {
                        AlertWarning(InfoString.SetContainString("Email"));
                        return(View(model));
                    }
                    model.User.CreateBy   = GetCurrentInstance().UserName;
                    model.User.CreateDate = DateTime.Now;
                    var result = await _userManager.CreateAsync(model.User, model.User.PasswordHash);

                    if (result.Succeeded)
                    {
                        //add user to group
                        foreach (var item in model.Groups)
                        {
                            if (item.IsCheck)
                            {
                                _groupService.AddUserToGroup(model.User.Id, item.Id);
                            }
                        }
                        _groupService.CommitChanges();
                        AlertSuccess(InfoString.CREATE_SUCCESSFULL);
                    }
                }
                catch (Exception ex)
                {
                    Log(ex);
                    AlertError(InfoString.ERROR_SYSTEM);
                }
                return(RedirectToAction("Index"));
            }
            AlertWarning(InfoString.INVALID_INFO);
            return(View(model));
        }