Exemple #1
0
        /// <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);
        }
Exemple #2
0
 public JsonResult Edit(Employee employee)
 {
     db.Entry(employee).State = EntityState.Modified;
     db.SaveChanges();
     // Thread.Sleep(2000);
     return(Json(employee, JsonRequestBehavior.AllowGet));
 }
Exemple #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));
        }
Exemple #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());
        }
 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"));
     }
 }
Exemple #6
0
        //  [ValidateAntiForgeryToken]
        public JsonResult Edit(Department department)
        {
            //Thread.Sleep(2000);
            db.Entry(department).State = EntityState.Modified;
            db.SaveChanges();

            return(Json(department, JsonRequestBehavior.AllowGet));
        }
 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));
 }
Exemple #8
0
 public ActionResult Edit(Employee1 emp)
 {
     if (ModelState.IsValid)
     {
         db.Entry(emp).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(emp));
 }
Exemple #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));
 }
Exemple #10
0
        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());
        }
Exemple #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));
 }
 public virtual void Update(T entity)
 {
     dbset.Attach(entity);
     dataContext.Entry(entity).State = EntityState.Modified;
 }
Exemple #13
0
 public void Modify(T entity)
 {
     context.Entry <T>(entity).State = System.Data.Entity.EntityState.Modified;
 }
 public void Update(T objRecord)
 {
     dbEntity.Attach(objRecord);
     db.Entry(objRecord).State = System.Data.Entity.EntityState.Modified;
 }
        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));
        }