Exemplo n.º 1
0
        public static ResponResultViewModel Update(MenuAccessViewModel entity)
        {
            ResponResultViewModel result = new ResponResultViewModel();

            try
            {
                using (var db = new MinProContext())
                {
                    if (entity.id == 0)
                    {
                        t_menu_access ma = new t_menu_access();
                        ma.menu_id    = entity.menu_id;
                        ma.role_id    = entity.role_id;
                        ma.created_by = 1;
                        ma.created_on = DateTime.Now;

                        db.t_menu_access.Add(ma);
                        db.SaveChanges();
                        result.Entity = entity;
                    }
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }
            return(result);
        }
Exemplo n.º 2
0
        public static ResponseResult Create(MenuAccessViewModel entity)
        {
            ResponseResult result = new ResponseResult();

            using (var db = new XBC_Context())
            {
                t_menu_access ma = new t_menu_access();
                ma.role_id = entity.role_id;
                ma.menu_id = entity.menu_id;

                ma.created_by = entity.UserId;
                ma.created_on = DateTime.Now;

                db.t_menu_access.Add(ma);
                db.SaveChanges();

                var         json = new JavaScriptSerializer().Serialize(ma);
                t_audit_log log  = new t_audit_log();
                log.type        = "Insert";
                log.json_insert = json;

                log.created_by = entity.UserId;
                log.created_on = DateTime.Now;
                db.t_audit_log.Add(log);

                db.SaveChanges();

                entity.id     = ma.id;
                result.Entity = entity;
            }
            return(result);
        }
Exemplo n.º 3
0
        public static ResponResultViewModel Delete(long id)
        {
            ResponResultViewModel result = new ResponResultViewModel();

            try
            {
                using (var db = new MinProContext())
                {
                    t_menu_access ma = db.t_menu_access.Where(o => o.id == id).FirstOrDefault();
                    if (ma == null)
                    {
                        result.Success = false;
                        result.Message = "Menu Access Not Found";
                    }
                    else
                    {
                        result.Entity = ma;
                        db.t_menu_access.Remove(ma);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }
            return(result);
        }
Exemplo n.º 4
0
        public static ResponseResult Delete(MenuAccessViewModel entity)
        {
            ResponseResult result = new ResponseResult();

            using (var db = new XBC_Context())
            {
                t_menu_access ma = db.t_menu_access.Where(o => o.id == entity.id).FirstOrDefault();
                db.t_menu_access.Remove(ma);
                if (ma != null)
                {
                    object data = new
                    {
                        ma.id,
                        ma.menu_id,
                        ma.role_id
                    };
                    var         json = new JavaScriptSerializer().Serialize(data);
                    t_audit_log log  = new t_audit_log();
                    log.type        = "DELETE";
                    log.json_before = json;

                    log.created_by = entity.UserId;
                    log.created_on = DateTime.Now;

                    var json2 = new JavaScriptSerializer().Serialize(ma);
                    log.json_after = json2;
                    db.t_audit_log.Add(log);
                    db.SaveChanges();

                    result.Entity = entity;
                }
                else
                {
                    result.Success      = false;
                    result.ErrorMessage = " not found! ";
                }
            }
            return(result);
        }