Exemplo n.º 1
0
        public static string AddOrUpdateFunctionItem(string id, string ma, string name, string parentID, string href, string icon, string thutu)
        {
            AjaxResponse   response = new AjaxResponse();
            xRPDataContext dts      = new xRPDataContext();
            var            user     = (from u in dts.aspnet_Users where u.UserName == HttpContext.Current.User.Identity.Name select u).FirstOrDefault();

            try
            {
                string message = string.Empty;

                int    groupdID    = 0;
                string role        = string.Empty;
                bool   isExistName = false;//
                Sys_FunctionRepository repository = new Sys_FunctionRepository();

                //response.IsSuccess = true;
                //response.Message = "Cập nhật thành công";

                Sys_Function entity = new Sys_Function();

                if (id != "")
                {
                    entity = repository.GetById(int.Parse(id));
                }
                else
                {
                    entity.NgayTao    = DateTime.Now;
                    entity.MaNguoiTao = user.UserId;
                }
                entity.NgayThayDoi    = DateTime.Now;
                entity.MaNguoiThayDoi = user.UserId;
                entity.Ma             = ma;
                entity.TenChucNang    = name;
                entity.ParentID       = int.Parse(parentID);
                entity.Href           = href;
                entity.Icon           = icon;
                entity.Position       = 1;
                entity.PhanHeID       = 1;
                entity.ThuTu          = int.Parse(thutu);
                if (id == "0")
                {
                    repository.InsertOnSubmit(entity);
                }
                repository.SubmitChanges();
                response.IsSuccess = true;
                response.Message   = "Cập nhật thành công";
            }
            catch (Exception ex)
            {
                response.IsSuccess = false;
                response.Message   = (ex.Message + ex.StackTrace).EncodeJsString();
            }
            return(JsonConvert.SerializeObject(response));
        }