public ActionResult Edit([Bind(Include = "UserID,UserFirstName,UserLastName,UserEmail,UserPassword")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
Example #2
0
 public ActionResult Edit([Bind(Include = "MissionID,MissionName,MissionPresident,MissionAddress,City,Country,DominantReligion,Flag")] Mission mission)
 {
     if (ModelState.IsValid)
     {
         db.Entry(mission).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(mission));
 }
Example #3
0
 public ActionResult Edit([Bind(Include = "ID,Name,PhoneNumber,Address,Zipcode")] Store store)
 {
     if (ModelState.IsValid)
     {
         db.Entry(store).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(store));
 }
 public ActionResult Edit([Bind(Include = "MissionQuestionID,MissionID,MissionName,MissionPresident,MissionAddress,MissionCity,MissionCountry,DominantReligion,Flag,MissionLanguage,MissionClimate,UserID,UserFirstName,UserLastName,UserEmail,UserPassword,Question,Ansswer")] UserMissionQuestion userMissionQuestion)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userMissionQuestion).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(userMissionQuestion));
 }
 public ActionResult Edit([Bind(Include = "Id,Email,EmailConfirmed,PasswordHash,SecurityStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEndDateUtc,LockoutEnabled,AccessFailedCount,UserName")] ApplicationUser applicationUser)
 {
     if (ModelState.IsValid)
     {
         db.Entry(applicationUser).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(applicationUser));
 }
 public ActionResult Edit([Bind(Include = "MissionQuestionID,MissionID,UserID,Question,Ansswer")] MissionQuestion missionQuestion)
 {
     if (ModelState.IsValid)
     {
         db.Entry(missionQuestion).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("QuestionPage", "UserMissionQuestions", new { id = missionQuestion.MissionID }));
     }
     return(View(missionQuestion));
 }
 public ActionResult Edit([Bind(Include = "ID,Name,UPC,CategoryID,Amount,Units,IsGMO,IsCO,IsLG")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryID = new SelectList(db.Categories, "ID", "Name", product.CategoryID);
     return(View(product));
 }
Example #8
0
 public ActionResult Edit([Bind(Include = "ID,Label,DateCreated,ListPriorityID")] ShoppingList shoppingList)
 {
     if (ModelState.IsValid)
     {
         db.Entry(shoppingList).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ListPriorityID = new SelectList(db.ListPriorities, "ListPriorityID", "Label", shoppingList.ListPriorityID);
     return(View(shoppingList));
 }
 public ActionResult Edit([Bind(Include = "PriceID,Value,ProductID,StoreID,Date")] Price price)
 {
     if (ModelState.IsValid)
     {
         db.Entry(price).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProductID = new SelectList(db.Products, "ID", "Name", price.ProductID);
     ViewBag.StoreID   = new SelectList(db.Stores, "ID", "Name", price.StoreID);
     return(View(price));
 }
        public ActionResult Edit([Bind(Include = "ItemID,ListID,ProductID,StoreID,Quantity")] ListItem listItem)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Entry(listItem).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.");
            }

            ViewBag.ProductID = new SelectList(db.Products, "ID", "Name", listItem.ProductID);
            ViewBag.ListID    = new SelectList(db.ShoppingLists, "ID", "Label", listItem.ListID);
            ViewBag.StoreID   = new SelectList(db.Stores, "ID", "Name", listItem.StoreID);
            return(View(listItem));
        }
Example #11
0
 public void Update(StepAddSubTotalValue entity)
 {
     db.Entry(entity).State = EntityState.Modified;
 }
        public override void Execute(int databaseId, AbacusContext source, AzureContext destination)
        {
            Logger.Log("Starting CustomerAccounts synchronization");

            var sourceQuery = $@"EXEC dbo.[CUReportCUAccounts]
                @ValueDate = '{_parameters.ValueDate}',
                @CurrencyID = '{_parameters.CurrencyId}',
                @BranchID = '{_parameters.BranchId}',
                @AccNoStart = '{_parameters.AccNoStart}',
                @AccNoEnd = '{_parameters.AccNoEnd}',
                @ActiveState = '{_parameters.ActiveState}',
                @GroupIDs = '{_parameters.GroupIDs}',
                @ProductTypes = '{_parameters.ProductTypes}',
                @ProductID = '{_parameters.ProductID}',
                @LoanStatus = '{_parameters.LoanStatus}',
                @LoanSourceOfFundsID = '{_parameters.LoanSourceOfFundsID}',
                @LoanReasonID = '{_parameters.LoanReasonID}',
                @DistrictCodeID = '{_parameters.DistrictCodeID}',
                @PortfolioID = '{_parameters.PortfolioID}',
                @CustomerTypes = '{_parameters.CustomerTypes}',
                @RefinancedLoans = '{_parameters.RefinancedLoans}',
                @RefinanceStart = '{_parameters.RefinanceStart}',
                @RefinanceEnd = '{_parameters.RefinanceEnd}',
                @OrderBy = '{_parameters.OrderBy}',
                @NumResults = '{_parameters.NumResults}',
                @CheckDigit = '{_parameters.CheckDigit}'";

            try
            {
                using var command = source.Database.GetDbConnection().CreateCommand();

                command.CommandText = sourceQuery;
                command.CommandType = CommandType.Text;

                command.Connection.Open();

                using var result = command.ExecuteReader();

                var sourceEntities = _factory
                                     .CreateMany(result)
                                     .AsEnumerable();

                var destinationEntities = destination.CustomerAccounts
                                          .Where(x => x.DatabaseId == databaseId);

                var entitiesToDelete = destinationEntities.Except(sourceEntities);
                var entitiesToAdd    = sourceEntities.Except(destinationEntities);
                var entitiesToSync   = sourceEntities
                                       .Except(entitiesToDelete)
                                       .Except(entitiesToAdd);

                foreach (var entity in entitiesToDelete)
                {
                    destination.Entry(entity).State = EntityState.Deleted;
                }

                destination.SaveChanges();

                foreach (var entity in entitiesToAdd)
                {
                    destination.Add(entity);
                }

                destination.SaveChanges();

                // Sync entititesToSync by setting properties in destination entity to value of source entity.
                // Something like this:
                //
                // foreach (var entity in entitiesToSync) {
                //   var destinationEntity = destionation.GetById(entity.Id);
                //   destinationEntity.LastName = entity.LastName;
                //   destination.Update(destinationEntity);
                // }
                // destination.SaveChanges();
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
            }
        }
 public void Update(Game entity)
 {
     db.Entry(entity).State = EntityState.Modified;
     Save();
 }
 public void Update(CategoryDict entity)
 {
     db.Entry(entity).State = EntityState.Modified;
     Save();
 }
Example #15
0
        // updates this ShoppingList's Listitems according to the current ListPriority.
        // If set to "Manual", then no changes will occur.
        public void SortShoppingListItems(int listID)
        {
            //System.Diagnostics.Debug.WriteLine("!!! shoppingList == null:" + (shoppingList == null));
            //System.Diagnostics.Debug.WriteLine("!!! shoppingList.ListItems == null:" + (shoppingList.ListItems == null));
            //shoppingList.ListItems = db.ListItems.Where(i => i.ListID == shoppingList.ID).ToList();
            //System.Diagnostics.Debug.WriteLine("!!! shoppingList.ListItems == null:" + (shoppingList.ListItems == null));

            ShoppingList shoppingList = db.ShoppingLists
                                        .Include(i => i.ListItems)
                                        .Include(i => i.ListPriority)
                                        .Where(i => i.ID == listID)
                                        .Single();



            // **************************************************************************
            // CASE 1: Best Price Sorting
            // **************************************************************************
            if (shoppingList.ListPriority.Label == ListPriority.BEST_PRICE)
            {
                foreach (ListItem l in shoppingList.ListItems)
                {
                    // (use HashSet to quickly resolve duplicates)
                    HashSet <Store> stores = new HashSet <Store>();
                    foreach (Price r in l.Product.Prices)
                    {
                        System.Diagnostics.Debug.WriteLine("***********************************");
                        System.Diagnostics.Debug.WriteLine("!!! 1) foreach Price.value: " + r.Value);
                        System.Diagnostics.Debug.WriteLine("***********************************");
                        stores.Add(r.Store);
                    }

                    // add the recent price entry for each store
                    List <Price> prices = new List <Price>();
                    foreach (Store s in stores)
                    {
                        System.Diagnostics.Debug.WriteLine("***********************************");
                        System.Diagnostics.Debug.WriteLine("!!! 2) foreach Store.name: " + s.Name);
                        System.Diagnostics.Debug.WriteLine("***********************************");
                        prices.Add(s.Prices
                                   .OrderByDescending(i => i.Date)
                                   .FirstOrDefault());
                    }
                    System.Diagnostics.Debug.WriteLine("***********************************");
                    System.Diagnostics.Debug.WriteLine("l.Product.Name:        " + l.Product.Name);
                    System.Diagnostics.Debug.WriteLine("l.Product.Prices.size: " + l.Product.Prices.Count());
                    System.Diagnostics.Debug.WriteLine("prices.size:           " + prices.Count());
                    System.Diagnostics.Debug.WriteLine("***********************************");
                    Price bestPrice = prices.OrderBy(i => i.Value).FirstOrDefault();
                    if (bestPrice == null)
                    {
                        l.StoreID = db.Stores.FirstOrDefault().ID;
                    }
                    else
                    {
                        // update the StoreID values
                        l.StoreID = bestPrice.StoreID;
                    }
                    db.Entry(l).State = EntityState.Modified;
                }
            }



            // **************************************************************************
            // CASE 2: Less Trips Sorting
            // **************************************************************************
            else if (shoppingList.ListPriority.Label == ListPriority.LESS_TRIPS)
            {
                //get all stores available to the list.
                HashSet <Store> stores = new HashSet <Store>();
                foreach (ListItem l in shoppingList.ListItems)
                {
                    List <Price> tempPrices = db.Prices.Where(i => i.ProductID == l.ProductID).ToList();
                    foreach (Price p in tempPrices)
                    {
                        stores.Add(p.Store);
                    }
                }

                //get all products in this list.
                HashSet <Product> products = new HashSet <Product>();
                foreach (ListItem l in shoppingList.ListItems)
                {
                    products.Add(l.Product);
                }


                // a list of products for each store
                List <HashSet <Product> > productLists = new List <HashSet <Product> >();

                // iterate over each Store!!!!
                foreach (Store s in stores)
                {
                    List <Price> storePrices = db.Prices
                                               .Include(i => i.Store)
                                               .Include(i => i.Product)
                                               .Where(i => i.StoreID == s.ID).ToList();

                    HashSet <Product> currentProducts = new HashSet <Product>();

                    foreach (Price r in storePrices)
                    {
                        if (products.Contains(r.Product))
                        {
                            currentProducts.Add(r.Product);
                        }
                    }
                    productLists.Add(currentProducts);
                }

                //order the list of Hashsets by Descending order of size
                productLists.OrderByDescending(i => i.Count);

                //populate the store in succession
                for (int i = 0; i < stores.Count; i++)
                {
                    foreach (Product p in productLists.ElementAt(i))
                    {
                        if (products.Contains(p))
                        {
                            List <ListItem> items = shoppingList.ListItems
                                                    .Where(j => j.ProductID == p.ID).ToList();
                            foreach (ListItem l in items)
                            {
                                l.StoreID         = stores.ElementAt(i).ID;
                                db.Entry(l).State = EntityState.Modified;
                            }
                            products.Remove(p);
                        }
                    }
                }
            }
            // **************************************************************************
            // CASE 3: Manual Sorting (do nothing to ListItem Data
            // **************************************************************************
            // Done!
            // db.SaveChanges();
        }
Example #16
0
 public void Update(KnowledgeArea entity)
 {
     db.Entry(entity).State = EntityState.Modified;
     Save();
 }
        public async Task <ActionResult> Edit(int?id, byte[] rowVersion)
        {
            string[] fieldsToBind = new string[] { "Name", "RowVersion" };

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var categoryToUpdate = await db.Categories.FindAsync(id);

            if (categoryToUpdate == null)
            {
                Category deletedCategory = new Category();
                TryUpdateModel(deletedCategory, fieldsToBind);
                ModelState.AddModelError(string.Empty,
                                         "Unable to save changes. The department was deleted by another user.");
                ViewBag.CategoryID = new SelectList(db.Categories, "ID", "FullName", deletedCategory.ID);
                return(View(deletedCategory));
            }

            if (TryUpdateModel(categoryToUpdate, fieldsToBind))
            {
                try
                {
                    db.Entry(categoryToUpdate).OriginalValues["RowVersion"] = rowVersion;
                    db.Entry(categoryToUpdate).State = EntityState.Modified;
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    var entry         = ex.Entries.Single();
                    var clientValues  = (Category)entry.Entity;
                    var databaseEntry = entry.GetDatabaseValues();
                    if (databaseEntry == null)
                    {
                        ModelState.AddModelError(string.Empty,
                                                 "Unable to save changes. The department was deleted by another user.");
                    }
                    else
                    {
                        var databaseValues = (Category)databaseEntry.ToObject();

                        if (databaseValues.Name != clientValues.Name)
                        {
                            ModelState.AddModelError("Name", "Current value: "
                                                     + databaseValues.Name);
                        }


                        ModelState.AddModelError(string.Empty, "The record you attempted to edit "
                                                 + "was modified by another user after you got the original value. The "
                                                 + "edit operation was canceled and the current values in the database "
                                                 + "have been displayed. If you still want to edit this record, click "
                                                 + "the Save button again. Otherwise click the Back to List hyperlink.");
                        categoryToUpdate.RowVersion = databaseValues.RowVersion;
                    }
                }
                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.");
                }
            }
            ViewBag.ProductID = new SelectList(db.Products, "ID", "FullName", categoryToUpdate.ID);


            return(View(categoryToUpdate));
        }
 public void Update(Question entity)
 {
     db.Entry(entity).State = EntityState.Modified;
     Save();
 }