Ejemplo n.º 1
0
        //更新
        public IActionResult Update(ForCase forCase)
        {
            var casedetail = new Casedetail();
            var thecase    = new Thecase();

            foreach (PropertyInfo info in typeof(Thecase).GetProperties())
            {
                PropertyInfo pro = typeof(ForCase).GetProperty(info.Name);
                if (pro != null)
                {
                    info.SetValue(thecase, pro.GetValue(forCase));
                }
            }
            foreach (PropertyInfo info in typeof(Casedetail).GetProperties())
            {
                PropertyInfo pro = typeof(ForCase).GetProperty(info.Name);
                if (pro != null)
                {
                    info.SetValue(casedetail, pro.GetValue(forCase));
                }
            }
            thecase.Uid    = caseService.ShowDetail(forCase.Cid).Uid;
            thecase.Toname = relationService.ShowDetail(forCase.Uid2).Name;
            casedetail.Uid = forCase.Uid2;
            caseService.Update(thecase);
            detailservice.Update(casedetail);
            return(Redirect(Url.Action("Detail", "_Case") + $"?cid={forCase.Cid}"));
        }
Ejemplo n.º 2
0
        public Casedetail ShowDetail(int cid)
        {
            Casedetail casedetail = null;

            using (var dbContext = new CasemanaContext())
            {
                casedetail = dbContext.Casedetail.FirstOrDefault(x => x.Cid == cid);
            }
            return(casedetail);
        }
Ejemplo n.º 3
0
        public int Create(Casedetail casedetail)
        {
            int count = 0;

            using (var dbContext = new CasemanaContext())
            {
                dbContext.Casedetail.Add(casedetail);
                count = dbContext.SaveChanges();
            }
            return(casedetail.Cid);
        }
Ejemplo n.º 4
0
        //更新
        public int Update(Casedetail casedetail)
        {
            int count = 0;

            using (var dbContext = new CasemanaContext())
            {
                var x = dbContext.Casedetail.FirstOrDefault(u => u.Cid == casedetail.Cid);
                foreach (PropertyInfo info in typeof(Casedetail).GetProperties())
                {
                    PropertyInfo pro = typeof(Casedetail).GetProperty(info.Name);
                    if (pro != null)
                    {
                        info.SetValue(x, pro.GetValue(casedetail));
                    }
                }
                dbContext.Casedetail.Update(x);
                count = dbContext.SaveChanges();
            }
            return(casedetail.Cid);
        }
Ejemplo n.º 5
0
        public int Del(int cid)
        {
            int count = 0;

            using (var dbContext = new CasemanaContext())
            {
                var casedetail = new Casedetail()
                {
                    Cid = cid
                };
                dbContext.Casedetail.Attach(casedetail);
                dbContext.Casedetail.Remove(casedetail);
                //将要删除的对象附加到EF容器中
                //context.Users.Attach(user);
                ////Remove()起到了标记当前对象为删除状态,可以删除
                //context.Users.Remove(user);
                //context.SaveChanges();
                //Console.WriteLine("删除成功");
                count = dbContext.SaveChanges();
            }
            return(count);
        }
Ejemplo n.º 6
0
        public IActionResult Create(ForCase forCase)
        {
            int count      = 0;
            var casedetail = new Casedetail()
            {
                Uid        = forCase.Uid2,
                ModifyDate = DateTime.Now,
                Prior      = forCase.Prior,
                Detail     = forCase.Detail,
                Previous   = forCase.Previous,
            };
            var cid = detailservice.Create(casedetail);

            if (cid > 0)
            {
                var  json      = HttpContext.Request.Cookies["user"];
                User loginuser = JsonConvert.DeserializeObject <User>(json);
                var  thecase   = new Thecase()
                {
                    Cid    = cid,
                    Uid    = loginuser.detail.Uid,
                    Pid    = forCase.Pid,
                    Unid   = forCase.Unid,
                    Proid  = loginuser.relation.Proid,
                    Ctitle = forCase.Ctitle,
                    Name   = loginuser.detail.Uname,
                    State  = "enable",
                    Toname = relationService.ShowDetail(forCase.Uid2).Name,
                };
                count = caseService.Create(thecase);
                if (count == 0)
                {
                    detailservice.Del(cid);
                }
            }
            return(Redirect(Url.Action("Index", "_Case")));
            //else
        }