コード例 #1
0
        public IActionResult Put([FromODataUri] Guid key, DoctorSetting doctorsetting)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            using (var trans = context.Database.BeginTransaction())
            {
                try
                {
                    if (context.DoctorSettings.Find(key) == null)
                    {
                        return(NotFound());
                    }
                    //context = new ApplicationDbContext(context.Options);
                    var local = context.DoctorSettings.Local.FirstOrDefault(it => it.DoctorSettingID.Equals(key));
                    if (local != null)
                    {
                        context.Entry(local).State = EntityState.Detached;
                    }


                    context.Entry(doctorsetting).State = EntityState.Modified;
                    context.SaveChanges();
                    trans.Commit();
                    return(Ok(doctorsetting));
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    return(BadRequest(ex));
                }
            }
        }
コード例 #2
0
        public IActionResult Post(DoctorSetting doctorsetting)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            using (var trans = context.Database.BeginTransaction())
            {
                try
                {
                    context.DoctorSettings.Add(doctorsetting);
                    context.SaveChanges();
                    trans.Commit();
                    return(Ok(doctorsetting));
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    return(BadRequest(ex));
                }
            }
        }