コード例 #1
0
ファイル: Repository.cs プロジェクト: ztxyzu/wx_public
        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="tobject"></param>
        /// <returns></returns>
        public virtual int Delete(TObject tobject)
        {
            var name = tobject.GetType().Name;

            if (name == "Building" || name == "Meter" || name == "Organization")
            {
                VO.Common.MeterCache.Init();
            }
            if (name == "User" || name == "Building" || name == "Organization")
            {
                VO.Common.UserCache.Init();
            }
            try
            {
                var entry = db.Entry(tobject);
                DbSet.Remove(tobject);
                if (!shareContext)
                {
                    return(db.SaveChanges());
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                Console.WriteLine(dbEx.Message);
                throw dbEx;
            }
            return(0);
        }
コード例 #2
0
 public JsonResult Edit(Employee employee)
 {
     db.Entry(employee).State = EntityState.Modified;
     db.SaveChanges();
     // Thread.Sleep(2000);
     return(Json(employee, JsonRequestBehavior.AllowGet));
 }
コード例 #3
0
        public async Task <IHttpActionResult> PutEmp(int id, Emp emp)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != emp.Id)
            {
                return(BadRequest());
            }

            db.Entry(emp).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmpExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #4
0
        public async Task <IActionResult> PutEmp(int id, Emp emp)
        {
            if (id != emp.empid)
            {
                return(BadRequest());
            }

            _context.Entry(emp).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmpExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #5
0
 public async Task <IActionResult> AddEmployee(Employee emp)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (emp.ID == 0)
             {
                 _Db.tbl_Employee.Add(emp);
                 await _Db.SaveChangesAsync();
             }
             else
             {
                 _Db.Entry(emp).State = EntityState.Modified;
                 await _Db.SaveChangesAsync();
             }
             return(RedirectToAction("EmployeeList"));
         }
         return(View());
     }
     catch (Exception e)
     {
         return(RedirectToAction("EmployeeList"));
     }
 }
コード例 #6
0
        //  [ValidateAntiForgeryToken]
        public JsonResult Edit(Department department)
        {
            //Thread.Sleep(2000);
            db.Entry(department).State = EntityState.Modified;
            db.SaveChanges();

            return(Json(department, JsonRequestBehavior.AllowGet));
        }
コード例 #7
0
 public ActionResult Edit([Bind(Include = "EmpId,Ename,Edesig,Edoj")] Emp emp)
 {
     if (ModelState.IsValid)
     {
         db.Entry(emp).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(emp));
 }
コード例 #8
0
 public ActionResult Edit(Employee1 emp)
 {
     if (ModelState.IsValid)
     {
         db.Entry(emp).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(emp));
 }
コード例 #9
0
 public ActionResult Edit([Bind(Include = "EId,EName,Email,Phone,MaritalStatus,State,City")] Employee1 employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employee));
 }
コード例 #10
0
ファイル: EmpController.cs プロジェクト: rkailash/EmpAPI
        public async Task <IActionResult> UpdateEmp(long id, Employee emp)
        {
            if (id != emp.Id)
            {
                return(BadRequest());
            }

            _context.Entry(emp).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
コード例 #11
0
 public HttpResponseMessage UpdateEmployee(Employee emp)
 {
     if (emp == null)
     {
         throw new ArgumentNullException("No emp item");
     }
     empContext.Entry(emp).State = EntityState.Modified;
     empContext.SaveChanges();
     //var dbemp = empContext.Employees.ToList();
     //int index = dbemp.FindIndex(p => p.EmployeeID == emp.EmployeeID);
     //if (index == -1)
     //{
     //    return Request.CreateResponse(HttpStatusCode.BadRequest, "No emp item");
     //}
     //dbemp.RemoveAt(index);
     //dbemp.Add(emp);
     //empContext.SaveChanges();
     return(Request.CreateResponse(HttpStatusCode.OK, emp));
 }
コード例 #12
0
 public virtual void Update(T entity)
 {
     dbset.Attach(entity);
     dataContext.Entry(entity).State = EntityState.Modified;
 }
コード例 #13
0
 public void Modify(T entity)
 {
     context.Entry <T>(entity).State = System.Data.Entity.EntityState.Modified;
 }
コード例 #14
0
 public void Update(T objRecord)
 {
     dbEntity.Attach(objRecord);
     db.Entry(objRecord).State = System.Data.Entity.EntityState.Modified;
 }
コード例 #15
0
        public ActionResult Create([Bind(Include = "EmployeeID,FirstName,LastName,Reference,ManualRefrence")] Employee employee)
        {
            //initialization

            // take the reference request
            string ReferenceBuff = "";

            try
            {
                ReferenceBuff = Request["Reference"].ToString();
            }
            catch (NullReferenceException)
            {
                ReferenceBuff = "";
            }
            //initialize employee instance to null
            Employee empRef = null;
            //initialize the current date to use current year
            DateTime date = DateTime.Now;

            //initialize string for manual reference
            string ManualRef = "";

            if (ReferenceBuff == "")
            {
                empRef = null;
            }
            else
            {
                try
                {
                    empRef = db.Employees.First(x => x.Reference == ReferenceBuff);
                }
                catch (InvalidOperationException)
                {
                    empRef = null;
                }

                if (empRef != null)
                {
                    return(RedirectToAction("ErrorPage"));
                }
                else
                {
                    ManualRef = "FSR-WL/" + ReferenceBuff + "/" + date.Year;
                }
            }

            if (ModelState.IsValid)
            {
                try
                {
                    db.Employees.Add(employee);
                    db.SaveChanges();
                    if (ReferenceBuff == "")
                    {
                        var refer = addRef(employee);
                        employee.Reference = refer;
                    }
                    else
                    {
                        employee.Reference = ManualRef;
                    }
                    db.SaveChanges();
                }
                catch (DbUpdateException)
                {
                    db.Entry(employee).State = EntityState.Deleted;
                    db.SaveChanges();
                    return(RedirectToAction("ErrorPage"));
                }

                return(RedirectToAction("Index"));
            }


            //db.SaveChanges();
            return(View(employee));
        }