示例#1
0
        public async Task <IActionResult> PutInventory(int id, Inventory inventory)
        {
            if (id != inventory.InventoryId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
示例#2
0
        public async Task <IActionResult> PutAsset(Guid id, Asset asset)
        {
            if (id != asset.AssetId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
示例#3
0
        public async Task <IActionResult> PutStaff(int id, Staff staff)
        {
            if (id != staff.StaffId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
示例#4
0
        public async Task <IActionResult> PutAsset(Guid id, Asset asset)
        {
            if (id != asset.AssetId)
            {
                _logger.LogDebug($"Invalid asset {id} provided.");
                return(BadRequest());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                if (!AssetExists(id))
                {
                    _logger.LogError($"Asset with ID {id} does not exist. Details: {ex.Message}");
                    return(NotFound());
                }
                else
                {
                    _logger.LogError($"Details: {ex.Message}");
                    throw;
                }
            }

            return(NoContent());
        }
示例#5
0
 public ActionResult Edit(OSSystem ossystem)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ossystem).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(ossystem));
 }
示例#6
0
 public ActionResult Edit(Building building)
 {
     if (ModelState.IsValid)
     {
         db.Entry(building).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(building));
 }
示例#7
0
 public ActionResult Edit([Bind(Include = "ID,Cash,Stock,Reits,ETF,Bond,Property,Loan,Debt,CPFOrdinary,CPFMedisave,CPFSpecial,Amount,RecordDate")] AssetHistory assetHistory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(assetHistory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(assetHistory));
 }
 public ActionResult Edit(WorkStationType workstationtype)
 {
     if (ModelState.IsValid)
     {
         db.Entry(workstationtype).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(workstationtype));
 }
示例#9
0
 public ActionResult Edit(AssetStatus assetstatus)
 {
     if (ModelState.IsValid)
     {
         db.Entry(assetstatus).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(assetstatus));
 }
示例#10
0
        public async Task DeleteAssetAsync(int assetId)
        {
            var context = new AssetContext();
            var asset   = new Asset {
                Id = assetId
            };

            context.Assets.Attach(asset);
            context.Entry(asset).State = EntityState.Deleted;
            await context.SaveChangesAsync();
        }
示例#11
0
 public ActionResult Edit([Bind(Include = "ID,StockID,Amount")] Profit profit)
 {
     if (ModelState.IsValid)
     {
         db.Entry(profit).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.StockID = new SelectList(db.Stocks, "ID", "Code", profit.StockID);
     return(View(profit));
 }
示例#12
0
 public ActionResult Edit([Bind(Include = "ID,StockID,Quantity,Cost")] Portfolio portfolio)
 {
     if (ModelState.IsValid)
     {
         db.Entry(portfolio).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.StockID = new SelectList(db.Stocks.OrderBy(o => o.Name).ToList(), "ID", "Name", portfolio.StockID);
     return(View(portfolio));
 }
示例#13
0
 public ActionResult Edit([Bind(Include = "CashID,CashType,BankName,BankAccountName,BankAccountNo,Currency,Amount,MaturityDate")] Cash cash)
 {
     if (ModelState.IsValid)
     {
         cash.UpdatedDate     = DateTime.Now;
         db.Entry(cash).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(cash));
 }
示例#14
0
 public ActionResult Edit([Bind(Include = "ID,StockID,Amount,PayDate")] Divident divident)
 {
     if (ModelState.IsValid)
     {
         db.Entry(divident).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.StockID = new SelectList(db.Stocks.OrderBy(o => o.Name).ToList(), "ID", "Name", divident.StockID);
     return(View(divident));
 }
示例#15
0
 public ActionResult Edit([Bind(Include = "ID,StockID,Action,Price,Quantity,OrderDate")] Transaction transaction)
 {
     if (ModelState.IsValid)
     {
         db.Entry(transaction).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.StockID = new SelectList(db.Stocks, "ID", "Code", transaction.StockID);
     return(View(transaction));
 }
示例#16
0
 public ActionResult Edit(Branch branch)
 {
     if (ModelState.IsValid)
     {
         db.Entry(branch).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DivisionID = new SelectList(db.Divisions, "DivisionID", "DivisionName", branch.DivisionID);
     return(View(branch));
 }
示例#17
0
 public ActionResult Edit(Software software)
 {
     if (ModelState.IsValid)
     {
         db.Entry(software).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.OSSystemID = new SelectList(db.OSSystems, "OSSystemID", "OSSystemname", software.OSSystemID);
     return(View(software));
 }
示例#18
0
        public ActionResult Edit([Bind(Include = "ID,Code,Name,Exchange,Currency,Category,Price")] Stock stock)
        {
            if (ModelState.IsValid)
            {
                db.Entry(stock).State = EntityState.Modified;
                db.SaveChanges();

                StockPriceService.UpdateStockPrice(stock.Code);
                return(RedirectToAction("Index"));
            }
            return(View(stock));
        }
示例#19
0
 public ActionResult Edit(AssetType assettype)
 {
     if (ModelState.IsValid)
     {
         db.Entry(assettype).State = EntityState.Modified;
         assettype.CreatedOn       = assettype.CreatedOn;
         assettype.LastUpdatedOn   = DateTime.Now;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(assettype));
 }
示例#20
0
 public ActionResult Edit(Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         //employee.LastUpdatedOn = DateTime.Now;
         //employee.CreatedOn = employee.CreatedOn;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     CreateEmployeeDropDowns(employee.Manager, employee.DivisionID, employee.BranchID, employee.BuildingID);
     CreateDivisionArray();
     return(View(employee));
 }
示例#21
0
 public ActionResult Edit(Division division)
 {
     if (ModelState.IsValid)
     {
         db.Entry(division).State = EntityState.Modified;
         division.LastUpdatedOn   = DateTime.Now;
         division.CreatedOn       = division.CreatedOn;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     //var query = from c in db.Employees
     //            select new { employeeid = c.EmployeeID, Names = c.EmployeeFirstName + " " + c.EmployeeLastName };
     //ViewBag.employeeid = new SelectList(query, "employeeid", "Names",division.EmployeeID);
     return(View(division));
 }
示例#22
0
        public async Task <int> SaveAssetAsync(Asset model)
        {
            var context = new AssetContext();

            if (model.Id == 0)
            {
                context.Assets.Add(model);
            }
            else
            {
                context.Assets.Attach(model);
                context.Entry(model).State = EntityState.Modified;
            }
            await context.SaveChangesAsync();

            return(model.Id);
        }
示例#23
0
        internal void SaveCurrentSummary()
        {
            List<AssetSummary> result = CalcSummary();

            AssetHistory assetHistory = db.AssetHistories.OrderByDescending(i => i.RecordDate).FirstOrDefault();
            if (assetHistory == null || assetHistory.RecordDate.Date != DateTime.Now.Date)
            {
                // if no record of current data
                assetHistory = new AssetHistory();
                db.AssetHistories.Add(assetHistory);
            }
            else
            {
                db.Entry(assetHistory).State = EntityState.Modified;
            }

            // set values
            assetHistory.RecordDate = DateTime.Now;
            foreach (AssetSummary a in result)
            {
                if (a.Category== "Cash")
                {
                    assetHistory.Cash = a.Amount;
                }
                else if (a.Category == "Stock")
                {
                    assetHistory.Stock = a.Amount;
                }
                else if (a.Category == "Reits")
                {
                    assetHistory.Reits = a.Amount;
                }
                else if (a.Category == "Bond")
                {
                    assetHistory.Bond = a.Amount;
                }
            }

            db.SaveChanges();
        }
 public void Update(T entity)
 {
     _context.Attach(entity);
     _context.Entry(entity).State = EntityState.Modified;
     _context.Entry(entity).Property(x => x.ID).IsModified = false;
 }
 public async Task UpdateAsset(int assetID, Asset asset)
 {
     _assetContext.Entry(asset).State = EntityState.Modified;
     await _assetContext.SaveChangesAsync();
 }
示例#26
0
        public ActionResult Edit(int id, FormCollection formCollection, string[] selectedSoftwares)
        {
            var assetToUpdate = db.Assets
                                .Include(i => i.Softwares)
                                .Where(i => i.AssetID == id)
                                .Single();

            if (TryUpdateModel(assetToUpdate, "", null, new string[] { "Softwares" }))
            {
                try
                {
                    UpdateAssetSoftwares(selectedSoftwares, assetToUpdate);

                    string json = JSONHelper.ToJSON(formCollection);

                    JObject jObject = JObject.Parse(json);
                    string  indexes = (string)jObject["assetSoftware.Index"];

                    string softwareID = "";
                    string install    = "";
                    string serial     = "";
                    string po         = "";

                    string currentVal = "";

                    var toDeletes = assetToUpdate.SoftwarePerAssets.ToList();
                    foreach (var soft in toDeletes)
                    {
                        db.SoftwarePerAssets.Remove(soft);
                    }

                    if (indexes != null)
                    {
                        List <string> splitIndexes = indexes.Split(',').Distinct().ToList <string>();
                        List <int>    addedIndexes = new List <int>();

                        SoftwarePerAsset sa;

                        for (int i = 0; i < splitIndexes.Count; i++)
                        {
                            currentVal = splitIndexes[i];
                            sa         = new SoftwarePerAsset();

                            for (int t = 0; t < jObject.Count; t++)
                            {
                                softwareID = (string)jObject["assetSoftware[" + currentVal + "].softName"];
                                serial     = (string)jObject["assetSoftware[" + currentVal + "].serial"];
                                install    = (string)jObject["assetSoftware[" + currentVal + "].installType"] == "" ? "1" : (string)jObject["assetSoftware[" + currentVal + "].installType"];
                                po         = (string)jObject["assetSoftware[" + currentVal + "].PO"];

                                //only add if software is not null
                                if (softwareID != "")
                                {
                                    sa.SoftwareID = Convert.ToInt32(softwareID);
                                    sa.SerialKey  = serial;
                                    sa.install    = Convert.ToInt32(install);
                                    sa.AssetID    = assetToUpdate.AssetID;
                                    sa.PONumber   = po;

                                    //Make sure the software is not added more than once
                                    if (!addedIndexes.Contains(sa.SoftwareID))
                                    {
                                        assetToUpdate.SoftwarePerAssets.Add(sa);
                                        addedIndexes.Add(sa.SoftwareID);
                                    }
                                }
                            }
                        }
                    }

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

                    //return RedirectToAction("Index");
                    GenerateFormSelectData(assetToUpdate.AssetID);
                    return(View(assetToUpdate));
                }
                catch (DataException)
                {
                    //Log the error (add a variable name after DataException)
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
                }
            }

            PopulateAssignedSoftware(assetToUpdate);
            GenerateFormSelectData(assetToUpdate.AssetID);

            return(View(assetToUpdate));
        }
示例#27
0
        public void UpdatePortfolio(Transaction tran, bool isRevert)
        {
            // get current portfolio
            Portfolio portfolio = (from o in db.Portfolios where o.StockID == tran.StockID select o).FirstOrDefault();

            if (portfolio == null)
            {
                // first transaction
                portfolio          = new Portfolio();
                portfolio.StockID  = tran.StockID;
                portfolio.Cost     = tran.Price;
                portfolio.Quantity = tran.Quantity;
                portfolio.Stock    = (from o in db.Stocks where o.ID == portfolio.StockID select o).FirstOrDefault();
                db.Portfolios.Add(portfolio);
                db.SaveChanges();
                return;
            }

            decimal totalCost = portfolio.Cost * portfolio.Quantity;

            if ((tran.Action == Models.Enum.Action.BUY && !isRevert) || (tran.Action == Models.Enum.Action.SELL && isRevert))
            {
                portfolio.Quantity += tran.Quantity;
                totalCost          += tran.Amount;
            }
            else
            {
                portfolio.Quantity -= tran.Quantity;
                totalCost          -= tran.Amount;
            }

            // update to db
            if (portfolio.Quantity == 0)
            {
                db.Portfolios.Remove(portfolio);

                // update profit (realised)
                decimal d = (tran.Price - portfolio.Cost) * tran.Quantity;
                if (d != 0)
                {
                    Profit p = (from o in db.Profits where o.StockID == tran.StockID select o).FirstOrDefault();
                    if (p == null)
                    {
                        p         = new Profit();
                        p.StockID = tran.StockID;
                        p.Amount  = d;
                        db.Profits.Add(p);
                    }
                    else
                    {
                        p.Amount         += d;
                        db.Entry(p).State = EntityState.Modified;
                    }
                }
            }
            else
            {
                portfolio.Cost            = totalCost / portfolio.Quantity;
                db.Entry(portfolio).State = EntityState.Modified;
            }
            db.SaveChanges();
        }