Пример #1
0
        public void Update(ProductViewModel product, string who)
        {
            using (var db = new SampleEntities())
            {
                var user = db.UserSet.Find(who);
                if (user == null)
                {
                    Clients.Caller.showErrorMessage("Could not find that user.");
                }
                else
                {
                    db.Entry(user)
                    .Collection(u => u.Connection)
                    .Query()
                    .Where(c => c.Connected == true)
                    .Load();

                    if (user.Connection == null)
                    {
                        Clients.Caller.showErrorMessage("The user is no longer connected.");
                    }
                    else
                    {
                        foreach (var connection in user.Connection)
                        {
                            Clients.Client(connection.ConnectionId)
                            .update(product);
                        }
                    }
                }
            }
        }
Пример #2
0
 public ActionResult Products_Update([DataSourceRequest] DataSourceRequest request, ProductViewModel product)
 {
     if (ModelState.IsValid)
     {
         using (var northwind = new SampleEntities())
         {
             // Create a new Product entity and set its properties from the posted ProductViewModel.
             var entity = new Product
             {
                 ProductID    = product.ProductID,
                 ProductName  = product.ProductName,
                 UnitsInStock = product.UnitsInStock
             };
             // Attach the entity.
             northwind.Products.Attach(entity);
             // Change its state to Modified so Entity Framework can update the existing product instead of creating a new one.
             northwind.Entry(entity).State = EntityState.Modified;
             // Or use ObjectStateManager if using a previous version of Entity Framework.
             // northwind.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);
             // Update the entity in the database.
             northwind.SaveChanges();
         }
     }
     // Return the updated product. Also return any validation errors.
     return(Json(new[] { product }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet));
 }
Пример #3
0
        public IHttpActionResult PutDepartment(int id, Department department)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != department.deptid)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DepartmentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #4
0
        public IHttpActionResult PutCarMake(int id, CarMake carMake)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != carMake.ID)
            {
                return BadRequest();
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CarMakeExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Пример #5
0
        public void Update(ProductVM product)
        {
            var pd = dbcontext.Products.Find(product.Id);

            dbcontext.Entry(pd).State = EntityState.Modified;
            dbcontext.SaveChanges();
        }
Пример #6
0
        public virtual void Update(DependencyViewModel dependency, ModelStateDictionary modelState)
        {
            var entity = dependency.ToEntity();

            db.GanttDependencies.Attach(entity);
            db.Entry(entity).State = EntityState.Modified;
            db.SaveChanges();
        }
Пример #7
0
        public virtual void Update(ResourceAssignmentViewModel assignment)
        {
            var entity = assignment.ToEntity();

            db.GanttResourceAssignments.Attach(entity);
            db.Entry(entity).State = EntityState.Modified;
            db.SaveChanges();
        }
Пример #8
0
        public void Update(ProductViewModel product)
        {
            if (!UpdateDatabase)
            {
                var target = One(e => e.ProductID == product.ProductID);

                if (target != null)
                {
                    target.ProductName  = product.ProductName;
                    target.UnitPrice    = product.UnitPrice;
                    target.UnitsInStock = product.UnitsInStock;
                    target.Discontinued = product.Discontinued;

                    if (product.CategoryID == null)
                    {
                        product.CategoryID = 1;
                    }

                    if (product.Category != null)
                    {
                        product.CategoryID = product.Category.CategoryID;
                    }
                    else
                    {
                        product.Category = new CategoryViewModel()
                        {
                            CategoryID   = (int)product.CategoryID,
                            CategoryName = entities.Categories.Where(s => s.CategoryID == product.CategoryID).Select(s => s.CategoryName).First()
                        };
                    }

                    target.CategoryID = product.CategoryID;
                    target.Category   = product.Category;
                }
            }
            else
            {
                var entity = new Product();

                entity.ProductID    = product.ProductID;
                entity.ProductName  = product.ProductName;
                entity.UnitPrice    = product.UnitPrice;
                entity.UnitsInStock = (short)product.UnitsInStock;
                entity.Discontinued = product.Discontinued;
                entity.CategoryID   = product.CategoryID;

                if (product.Category != null)
                {
                    entity.CategoryID = product.Category.CategoryID;
                }

                entities.Products.Attach(entity);
                entities.Entry(entity).State = EntityState.Modified;
                entities.SaveChanges();
            }
        }
Пример #9
0
 public ActionResult Edit([Bind(Include = "ID,Name")] CarMake carMake)
 {
     if (ModelState.IsValid)
     {
         db.Entry(carMake).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(carMake));
 }
Пример #10
0
 public virtual void Update(EmployeeDirectoryModel employee, ModelStateDictionary modelState)
 {
     if (ValidateModel(employee, modelState))
     {
         var entity = employee.ToEntity();
         db.EmployeeDirectory.Attach(entity);
         db.Entry(entity).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Пример #11
0
 public ActionResult Edit([Bind(Include = "UserID,Name,Address,ContactNo")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
        public ActionResult Edit(Document document)
        {
            if (ModelState.IsValid)
            {
                db.Entry(document).State = EntityState.Modified;
                db.SaveChanges();
                Index(document, "update");
                return(RedirectToAction("Index"));
            }

            return(View(document));
        }
Пример #13
0
        public virtual void Update(TaskViewModel task, ModelStateDictionary modelState)
        {
            if (ValidateModel(task, modelState))
            {
                if (string.IsNullOrEmpty(task.Title))
                {
                    task.Title = "";
                }

                var entity = task.ToEntity();
                db.Tasks.Attach(entity);
                db.Entry(entity).State = EntityState.Modified;
                db.SaveChanges();
            }
        }
Пример #14
0
        public ActionResult UpdateStickyNote(stickyNote stickynote)
        {
            StickyNote obj = new StickyNote();

            obj.Text            = stickynote.text;
            obj.Left            = stickynote.left;
            obj.Top             = stickynote.top;
            obj.Colour          = stickynote.colour;
            obj.Width           = stickynote.width;
            obj.Height          = stickynote.height;
            obj.Id              = stickynote.id;
            db.Entry(obj).State = EntityState.Modified;
            db.SaveChanges();
            return(Json(stickynote.id, JsonRequestBehavior.AllowGet));
        }
 public string Update_Entity(LegalEntity entity)
 {
     if (entity != null)
     {
         using (SampleEntities Obj = new SampleEntities())
         {
             var         entity_ = Obj.Entry(entity);
             LegalEntity EmpObj  = Obj.LegalEntities.Where(x => x.EntityId == entity.EntityId).FirstOrDefault();
             EmpObj.EntityName   = entity.EntityName;
             EmpObj.Abbreviation = entity.Abbreviation;
             Obj.SaveChanges();
             return("Entity Updated Successfully");
         }
     }
     else
     {
         return("Entity Not Updated! Try Again");
     }
 }
Пример #16
0
        public void Update(ProductViewModel product)
        {
            var entity = new Product();

            entity.ProductID    = product.ProductID;
            entity.ProductName  = product.ProductName;
            entity.UnitPrice    = product.UnitPrice;
            entity.UnitsInStock = (short)product.UnitsInStock;
            entity.Discontinued = product.Discontinued;
            entity.CategoryID   = product.CategoryID;

            if (product.Category != null)
            {
                entity.CategoryID = product.Category.CategoryID;
            }

            entities.Products.Attach(entity);
            entities.Entry(entity).State = EntityState.Modified;
            entities.SaveChanges();
        }
 public string Delete_Entity(LegalEntity entity)
 {
     if (entity != null)
     {
         using (SampleEntities Obj = new SampleEntities())
         {
             var Emp_ = Obj.Entry(entity);
             if (Emp_.State == System.Data.Entity.EntityState.Detached)
             {
                 Obj.LegalEntities.Attach(entity);
                 Obj.LegalEntities.Remove(entity);
             }
             Obj.SaveChanges();
             return("Entity Deleted Successfully");
         }
     }
     else
     {
         return("Entity Not Deleted! Try Again");
     }
 }
Пример #18
0
 public string Delete_Address(Address address)
 {
     if (address != null)
     {
         using (SampleEntities Obj = new SampleEntities())
         {
             var Emp_ = Obj.Entry(address);
             if (Emp_.State == System.Data.Entity.EntityState.Detached)
             {
                 Obj.Addresses.Attach(address);
                 Obj.Addresses.Remove(address);
             }
             Obj.SaveChanges();
             return("Address Deleted Successfully");
         }
     }
     else
     {
         return("Address Not Deleted! Try Again");
     }
 }
Пример #19
0
        public string Update_Employee(Employee Emp)
        {
            if (Emp != null)
            {
                using (SampleEntities db = new SampleEntities())
                {
                    var      Emp_        = db.Entry(Emp);
                    Employee employeeObj = db.Employees.Where(x => x.Emp_Id == Emp.Emp_Id).FirstOrDefault();
                    employeeObj.Emp_Name = Emp.Emp_Name;
                    employeeObj.Emp_City = Emp.Emp_City;
                    employeeObj.Emp_Age  = Emp.Emp_Age;

                    db.SaveChanges();
                    return("Employee updated successfully ");
                }
            }
            else
            {
                return("Error While Update");
            }
        }
Пример #20
0
 public string Delete_Employee(Employee Emp)
 {
     if (Emp != null)
     {
         using (SampleEntities db = new SampleEntities())
         {
             var Emp_ = db.Entry(Emp);
             if (Emp_.State == System.Data.Entity.EntityState.Detached)
             {
                 db.Employees.Attach(Emp);
                 db.Employees.Remove(Emp);
             }
             db.SaveChanges();
             return("Employee deleted successfully");
         }
     }
     else
     {
         return("Employee not deleted ! try again");
     }
 }
Пример #21
0
 public string UpdatePassneger(int id, PassengerView model)
 {
     try
     {
         tbl_Passenger entity = db.tbl_Passenger.Find(id);
         if (model != null)
         {
             entity.P_No            = model.P_No;
             entity.F_Name          = model.F_Name;
             entity.L_Name          = model.L_Name;
             entity.Phone           = model.Phone;
             db.Entry(entity).State = EntityState.Modified;
             db.SaveChanges();
             return("Passenger updated");
         }
         return("Model is null");
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
Пример #22
0
 public string Update_Address(Address address)
 {
     if (address != null)
     {
         using (SampleEntities Obj = new SampleEntities())
         {
             var     addr_  = Obj.Entry(address);
             Address EmpObj = Obj.Addresses.Where(x => x.AddressId == address.AddressId).FirstOrDefault();
             EmpObj.AddressLine1 = address.AddressLine1;
             EmpObj.City         = address.City;
             EmpObj.State        = address.State;
             EmpObj.Country      = address.Country;
             EmpObj.Zipcode      = address.Zipcode;
             Obj.SaveChanges();
             return("Address Updated Successfully");
         }
     }
     else
     {
         return("Address Not Updated! Try Again");
     }
 }
Пример #23
0
        // PUT api/Task/5
        public HttpResponseMessage PutTask(int id, TaskViewModel task)
        {
            if (ModelState.IsValid && id == task.TaskID)
            {
                var entity = new Task
                {
                    TaskID              = task.TaskID,
                    Title               = task.Title,
                    Start               = task.Start,
                    StartTimezone       = task.StartTimezone,
                    End                 = task.End,
                    EndTimezone         = task.EndTimezone,
                    Description         = task.Description,
                    RecurrenceRule      = task.RecurrenceRule,
                    RecurrenceException = task.RecurrenceException,
                    RecurrenceID        = task.RecurrenceID,
                    IsAllDay            = task.IsAllDay,
                    OwnerID             = task.OwnerID
                };

                db.Tasks.Attach(entity);
                db.Entry(entity).State = EntityState.Modified;

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Пример #24
0
 public virtual void Update(OrgChartConnection connection, ModelStateDictionary modelState)
 {
     db.OrgChartConnections.Attach(connection);
     db.Entry(connection).State = EntityState.Modified;
     db.SaveChanges();
 }
Пример #25
0
 public virtual void Update(OrgChartShape shape, ModelStateDictionary modelState)
 {
     db.OrgChartShapes.Attach(shape);
     db.Entry(shape).State = EntityState.Modified;
     db.SaveChanges();
 }