示例#1
0
        public ActionResult Edit(int?id, string[] selectedFacilities)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var employeeToUpdate = db.Employees.Include(e => e.Facilities).Where(i => i.Id == id && i.IsActive == true).SingleOrDefault();

            if (TryUpdateModel(employeeToUpdate, "",
                               new string[] { "Id", "UserName", "FirstName", "LastName", "Email", "IsAdmin", "Password" }))
            {
                try
                {
                    UpdateEmployeeFacilities(selectedFacilities, employeeToUpdate);

                    db.Entry(employeeToUpdate).State = EntityState.Modified;
                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
                catch (RetryLimitExceededException /* dex */)
                {
                    //Log the error (uncomment dex variable name and add a line here to write a log.
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
                }
            }

            PopulateAssignedFacilityData(employeeToUpdate);
            return(View(employeeToUpdate));
        }
 public ActionResult Edit([Bind(Include = "FacilityId,FacilityName,Description,Landmark,Address,City,State,ZipCode")] Facility facility)
 {
     if (ModelState.IsValid)
     {
         db.Entry(facility).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(facility));
 }
示例#3
0
    public void UpsertAthleteSizes(List <AthleteSizeUpsert> athleteSizes, string sportId, string athleteId)
    {
        foreach (var item in athleteSizes)
        {
            AthleteSize athleteSize = new AthleteSize()
            {
                Id           = item.Id.HasValue ? (int)item.Id : 0, // SQL Server will autogenerate identity if 0
                AthleteId    = athleteId,
                Size         = item.Size,
                SportsItemId = item.SportsItemId,
                SportId      = sportId
            };

            if (item.Id == null)
            {
                db.AthleteSizes.Add(athleteSize);
            }
            else
            {
                db.AthleteSizes.Attach(athleteSize);
                db.Entry(athleteSize).State = EntityState.Modified;
            }
        }

        db.SaveChanges();
    }
        public ActionResult Edit(EmployeeViewModel employee)
        {
            if (ModelState.IsValid)
            {
                var myEmployee = db.Employees.Find(employee.EmployeeId);
                myEmployee.UserName  = employee.UserName;
                myEmployee.FirstName = employee.FirstName;
                myEmployee.LastName  = employee.LastName;
                myEmployee.Email     = employee.Email;
                myEmployee.IsAdmin   = employee.IsAdmin;
                myEmployee.Password  = employee.Password;

                foreach (var item in db.EmplyoeesToFacilities)
                {
                    if (item.EmployeeID == employee.EmployeeId)
                    {
                        db.Entry(item).State = System.Data.Entity.EntityState.Deleted;
                    }
                }
                foreach (var item in employee.Facilities)
                {
                    if (item.Selected)
                    {
                        db.EmplyoeesToFacilities.Add(new EmployeeToFacility()
                        {
                            EmployeeID = employee.EmployeeId, FacilityId = item.Id
                        });
                    }
                }

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(employee));
        }
        public async Task <IActionResult> PutProducts(int id, Products products)
        {
            if (id != products.ProductId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> Edit(int id, [Bind("OrderID,OrderNumber,DateOrdered,CustomerName,CustomerAddress,OrderLines")] Order order)
        {
            if (id != order.OrderID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var existingOrder = _context.Orders
                                    .Where(o => o.OrderID == order.OrderID)
                                    .Include(o => o.OrderLines)
                                    .FirstOrDefault();

                for (var i = 0; i < order.OrderLines.Count; i++)
                {
                    if (order.OrderLines[i] == null)
                    {
                        order.OrderLines.Remove(order.OrderLines[i]);
                    }
                }

                existingOrder.OrderLines            = order.OrderLines;
                _context.Entry(existingOrder).State = EntityState.Modified;

                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OrderExists(order.OrderID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                // Catching duplicate OrderID exception
                catch (DbUpdateException ex)
                {
                    // send message to view
                    ModelState.AddModelError("OrderID", "An order with this ID already exists");
                    ViewData["ProductID"] = new SelectList(_context.Products, "ProductID", "ProductDescription");
                    return(View(order));
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductID"] = new SelectList(_context.Products, "ProductID", "ProductDescription");
            return(View(order));
        }
        public ActionResult Edit([Bind(Include = "ResourceId,ResourceName,Quantity,Description,Size,Color,Changed,PreviousValue,FacilityId")] Resource resource)
        {
            if (ModelState.IsValid)
            {
                resource.PreviousValue = resource.Quantity;
                var checkValue = resource.Changed;
                System.Diagnostics.Debug.WriteLine(checkValue);


                db.Entry(resource).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.FacilityId = new SelectList(db.Facilities, "FacilityId", "FacilityName", resource.FacilityId);
            return(View(resource));
        }
 public ActionResult Edit([Bind(Include = "ResourceId,ResourceName,Quantity,Description,Size,Color,Changed,PreviousValue,FacilityId")] Resource resource)
 {
     if (ModelState.IsValid)
     {
         if (resource.PreviousValue != resource.Quantity)
         {
             /*TempData["valueChanged"] = "Resource quantity updated from last time, New value is " + resource.Quantity;*/
             resource.PreviousValue = resource.Quantity;
             resource.Changed       = true;
         }
         db.Entry(resource).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.FacilityId = new SelectList(db.Facilities, "FacilityId", "FacilityName", resource.FacilityId);
     return(View(resource));
 }