public virtual void Delete(TEntity entityToDelete)
 {
     if (context.Entry(entityToDelete).State == EntityState.Detached)
     {
         dbSet.Attach(entityToDelete);
     }
     dbSet.Remove(entityToDelete);
 }
        public IHttpActionResult PutItem_transcation_inventory(int id, Item_transcation_inventory item_transcation_inventory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != item_transcation_inventory.Seq)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #3
0
        public async Task <IActionResult> PutEmployee(int id, Employee employee)
        {
            if (id != employee.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Пример #4
0
 public ActionResult Edit([Bind(Include = "CustomerID,FirstName,LastName,Phone,Address,City,State,Zip")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customer));
 }
 public ActionResult Edit([Bind(Include = "Id,Name,Gender,Email")] Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employee));
 }
Пример #6
0
 public ActionResult Edit([Bind(Include = "ID,Manufacturer,Name")] Car car)
 {
     if (ModelState.IsValid)
     {
         db.Entry(car).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(car));
 }
 public void Delete(User user)
 {
     using (var dataContext = new SampleDBContext())
     {
         dataContext.Roles.RemoveRange(dataContext.Roles.Where(x => x.UserId == user.UserId));
         dataContext.SaveChanges();
         dataContext.Entry(user).State = EntityState.Deleted;
         dataContext.SaveChanges();
     }
 }
Пример #8
0
 public ActionResult Edit([Bind(Include = "Id,FirstName,LastName,Email,PhoneNumber,DateOfBirth,DrivingLicense,IsInternalEmployee")] tblEmployee tblEmployee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tblEmployee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tblEmployee));
 }
Пример #9
0
 public ActionResult Edit([Bind(Include = "ID,Name,Car")] Person person)
 {
     if (ModelState.IsValid)
     {
         db.Entry(person).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(person));
 }
 public ActionResult Edit([Bind(Include = "StudentId,StudentName,EmailId,Age,Location,DoJ,Department")] Student student)
 {
     if (ModelState.IsValid)
     {
         db.Entry(student).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(student));
 }
        public async Task <IActionResult> Patch(
            [HttpTrigger(AuthorizationLevel.Anonymous, "patch", Route = "Contact/{id}")] HttpRequest req,
            ILogger log, int id)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            if (id < 0)
            {
                return(new BadRequestObjectResult("no identifier passed"));
            }

            var dbContact = await _context.Contacts.FirstOrDefaultAsync(x => x.ID == id);

            if (dbContact == null || dbContact.ID != id)
            {
                return(new NotFoundResult());
            }

            try
            {
                string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
                JsonPatchDocument <Contact> patchDoc = JsonConvert.DeserializeObject <JsonPatchDocument <Contact> >(requestBody);

                patchDoc.ApplyTo(dbContact);

                _context.Entry(dbContact).State = EntityState.Modified;
                var RowsAffected = await _context.SaveChangesAsync();

                if (RowsAffected > 0)
                {
                    return(new OkObjectResult(dbContact));
                }
            }
            catch (Exception e)
            {
                return(new BadRequestObjectResult(e.Message));
            }

            return(new BadRequestResult());
        }
Пример #12
0
 public ActionResult profile(HotelModelClass admin)
 {
     if (ModelState.IsValid)
     {
         db.Entry(admin).State = EntityState.Modified;
         db.SaveChanges();
         TempData["SuccessMessage"] = "your profile is updated";
         return(RedirectToAction("profile"));
     }
     else
     {
         return(View(admin));
     }
 }
Пример #13
0
        public ActionResult Update(int?id, string title, string body, DateTime datetime, string tags)
        {
            if (!IsAdmin)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                Post post = new Post();
                post.Title    = title;
                post.Body     = body;
                post.Datetime = datetime;
                post.Tags.Clear();

                tags = tags ?? string.Empty;
                string[] tagNames = tags.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);


                foreach (string tagName in tagNames)
                {
                    post.Tags.Add(GetTag(tagName));
                }

                if (!id.HasValue || id == -1)
                {
                    model.Posts.Add(post);
                    model.SaveChanges();
                }
                else
                {
                    post = model.Posts.Find(id);

                    post.Title    = title;
                    post.Body     = body;
                    post.Datetime = datetime;

                    model.Entry(post).State = System.Data.EntityState.Modified;
                    model.SaveChanges();
                }


                return(RedirectToAction("Details", new { id = post.Id }));
            }
        }
 public ActionResult profile(User user)
 {
     if (Session["User_Email"] != null)
     {
         if (ModelState.IsValid)
         {
             db.Entry(user).State = EntityState.Modified;
             db.SaveChanges();
             TempData["SuccessMessage"] = "your profile is updated";
             return(RedirectToAction("profile"));
         }
         else
         {
             return(View(user));
         }
     }
     else
     {
         return(RedirectToAction("LogIn"));
     }
 }
Пример #15
0
        public ActionResult Edit(Employee employee)
        {
            if (ModelState.IsValid)
            {
                SampleDBContext db             = new SampleDBContext();
                Employee        employeeFromDB = db.Employees.Single(x => x.Id == employee.Id);

                // Populate all the properties except EmailAddrees
                employeeFromDB.FullName        = employee.FullName;
                employeeFromDB.Gender          = employee.Gender;
                employeeFromDB.Age             = employee.Age;
                employeeFromDB.HireDate        = employee.HireDate;
                employeeFromDB.Salary          = employee.Salary;
                employeeFromDB.PersonalWebSite = employee.PersonalWebSite;

                db.Entry(employeeFromDB).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Details", new { id = employee.Id }));
            }
            return(View(employee));
        }
Пример #16
0
 public int Update(User e)
 {
     context.Entry(e).State = System.Data.Entity.EntityState.Modified;
     return(context.SaveChanges());
 }