Esempio n. 1
0
 public ActionResult ChinhSuaChucNang(string id)
 {
     if (SessionManager.CheckSession(ConstantValues.SessionKeyCurrentUser))
     {
         if (string.IsNullOrEmpty(id))
         {
             return(RedirectToAction("DanhSachChucNang", "Developer"));
         }
         var model = new ChucNangModel();
         model.ChucNangObj = xlchucnang.Doc(id);
         if (model.ChucNangObj == null)
         {
             return(RedirectToAction("DanhSachChucNang", "Developer"));
         }
         model.DanhSachChucNang = xlchucnang.DocDanhSachChucNangCapCha();
         var cn = model.DanhSachChucNang.Find(c => c.Id.ToString() == id);
         model.DanhSachChucNang.Remove(cn);
         return(View("ChinhSuaChucNang", model));
     }
     if (Request.Url != null)
     {
         SessionManager.RegisterSession(ConstantValues.SessionKeyUrl, Request.Url.AbsolutePath);
     }
     return(RedirectToAction("Index", "Login"));
 }
Esempio n. 2
0
        public ActionResult ChinhSuaChucNang(FormCollection collection)
        {
            if (SessionManager.CheckSession(ConstantValues.SessionKeyCurrentUser))
            {
                if (!string.IsNullOrEmpty(collection["save"].ToString()))
                {
                    string id = collection["chucNangId"].ToString();
                    if (string.IsNullOrEmpty(id))
                    {
                        return(RedirectToAction("DanhSachChucNang", "Developer"));
                    }
                    ChucNang chucNang = xlchucnang.Doc(id);
                    if (chucNang == null)
                    {
                        return(RedirectToAction("DanhSachChucNang", "Developer"));
                    }
                    NotifyModel thongBao   = new NotifyModel();
                    var         dsChucNang = xlchucnang.DocDanhSachChucNangCapCha();
                    try
                    {
                        var user = (NguoiDung)SessionManager.ReturnSessionObject(ConstantValues.SessionKeyCurrentUser);

                        int kichHoat = 0;
                        if (collection["kich_hoat"] != null && !string.IsNullOrEmpty(collection["kich_hoat"].ToString()) && collection["kich_hoat"].ToString() == "on")
                        {
                            kichHoat = 1;
                        }
                        chucNang.Ten       = collection["ten"].ToString();
                        chucNang.BieuTuong = collection["bieu_tuong"].ToString();
                        chucNang.LienKet   = collection["lien_ket"].ToString();
                        chucNang.IdCha     = collection["chuc_nang_cha"].ToString();
                        if (chucNang.IdCha != "0")
                        {
                            //hiện tại chỉ hỗ trợ cho 2 cấp thôi nên nếu có cha thì cấp con sẽ là 2
                            chucNang.CapDo = 2;
                        }
                        else
                        {
                            chucNang.CapDo = 1;
                        }
                        chucNang.NgayCapNhat    = Utility.ConvertToUnixTimestamp(DateTime.UtcNow);
                        chucNang.IdNguoiCapNhat = user.Id.ToString();
                        chucNang.SapXep         = int.Parse(collection["sap_xep"].ToString());
                        chucNang.KichHoat       = kichHoat;

                        if (xlchucnang.CapNhat(chucNang))
                        {
                            thongBao.TypeNotify = "alert-success";
                            thongBao.Message    = "Cập nhật thành công";
                        }
                        else
                        {
                            thongBao.TypeNotify = "alert-danger";
                            thongBao.Message    = "Cập nhật thất bại!";
                        }
                    }
                    catch (Exception)
                    {
                        thongBao.TypeNotify = "alert-danger";
                        thongBao.Message    = "Cập nhật thất bại!";
                    }
                    ViewBag.ThongBao = thongBao;
                    var model = new ChucNangModel();
                    model.ChucNangObj      = chucNang;
                    model.DanhSachChucNang = dsChucNang;
                    return(View("ChinhSuaChucNang", model));
                }
                return(RedirectToAction("DanhSachChucNang", "Developer"));
            }
            if (Request.Url != null)
            {
                SessionManager.RegisterSession(ConstantValues.SessionKeyUrl, Request.Url.AbsolutePath);
            }
            return(RedirectToAction("Index", "Login"));
        }