public async Task <IActionResult> PutAsset([FromRoute] int id, [FromBody] Asset asset)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != asset.AssetId)
            {
                return(BadRequest());
            }

            asset.UpdatedWhen = DateTimeOffset.Now;

            _context.Entry(asset).State = EntityState.Modified;
            _context.Entry(asset).Property(p => p.CreatedWhen).IsModified = false;

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

            return(NoContent());
        }
Ejemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "Id,Name,ShortName,Code")] AssetType assetType)
 {
     if (ModelState.IsValid)
     {
         db.Entry(assetType).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(assetType));
 }
Ejemplo n.º 3
0
 public ActionResult Edit([Bind(Include = "ID,Name,Type,AskingRent")] Asset asset)
 {
     if (ModelState.IsValid)
     {
         db.Entry(asset).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(asset));
 }
Ejemplo n.º 4
0
 public ActionResult Edit([Bind(Include = "Id,AssetEntryId,Notes")] Note note)
 {
     if (ModelState.IsValid)
     {
         db.Entry(note).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AssetEntryId = new SelectList(db.AssetEntries, "Id", "AssetId", note.AssetEntryId);
     return(View(note));
 }
 public ActionResult Edit([Bind(Include = "Id,AssetEntryId,Description,ServiceDate,ServiceingCostDecimal,PartsCostDecimal,TaxDecimal,ServiceBy")] ServiceOrRepairing serviceOrRepairing)
 {
     if (ModelState.IsValid)
     {
         db.Entry(serviceOrRepairing).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AssetEntryId = new SelectList(db.AssetEntries, "Id", "AssetId", serviceOrRepairing.AssetEntryId);
     return(View(serviceOrRepairing));
 }
 public ActionResult Edit([Bind(Include = "Id,AssetTypeId,Name,ShortName,GroupCode")] AssetGroup assetGroup)
 {
     if (ModelState.IsValid)
     {
         db.Entry(assetGroup).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AssetTypeId = new SelectList(db.AssetTypes, "Id", "Name", assetGroup.AssetTypeId);
     return(View(assetGroup));
 }
 public ActionResult Edit([Bind(Include = "Id,AssetEntryId,File")] Attchment attchment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(attchment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AssetEntryId = new SelectList(db.AssetEntries, "Id", "AssetId", attchment.AssetEntryId);
     return(View(attchment));
 }
 public ActionResult Edit([Bind(Include = "Id,AssetGroupId,AssetManufacurerId,Name,ShortName,Code,Description")] AssetModel assetModel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(assetModel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AssetGroupId       = new SelectList(db.AssetGroups, "Id", "Name", assetModel.AssetGroupId);
     ViewBag.AssetManufacurerId = new SelectList(db.AssetManufacurers, "Id", "Name", assetModel.AssetManufacurerId);
     return(View(assetModel));
 }
Ejemplo n.º 9
0
 public ActionResult Edit([Bind(Include = "Id,AssetEntryId,VendorId,ParchasePrice,ParchaseOrderNo,PurchaseDate")] Finance finance)
 {
     if (ModelState.IsValid)
     {
         db.Entry(finance).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AssetEntryId = new SelectList(db.AssetEntries, "Id", "AssetId", finance.AssetEntryId);
     ViewBag.VendorId     = new SelectList(db.Vendors, "Id", "VendorName", finance.VendorId);
     return(View(finance));
 }
 public ActionResult Edit([Bind(Include = "Id,OrganizationId,BranchId,AssetLocationId,AssetTypeId,AssetGroupId,AssetManufacurerId,AssetModelId,AssetId,Name,SerialNo,Status,Attachment")] AssetEntry assetEntry)
 {
     if (ModelState.IsValid)
     {
         _db.Entry(assetEntry).State = EntityState.Modified;
         _db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AssetGroupId       = new SelectList(_db.AssetGroups, "Id", "Name", assetEntry.AssetGroupId);
     ViewBag.AssetLocationId    = new SelectList(_db.AssetLocations, "Id", "Name", assetEntry.AssetLocationId);
     ViewBag.AssetManufacurerId = new SelectList(_db.AssetManufacurers, "Id", "Name", assetEntry.AssetManufacurerId);
     ViewBag.AssetModelId       = new SelectList(_db.AssetModels, "Id", "Name", assetEntry.AssetModelId);
     ViewBag.AssetTypeId        = new SelectList(_db.AssetTypes, "Id", "Name", assetEntry.AssetTypeId);
     ViewBag.BranchId           = new SelectList(_db.Branches, "Id", "Name", assetEntry.BranchId);
     ViewBag.OrganizationId     = new SelectList(_db.Organizations, "Id", "Name", assetEntry.OrganizationId);
     return(View(assetEntry));
 }
Ejemplo n.º 11
0
        public async Task <ActionResult <AssetProperty> > Patch([FromRoute] int asset_id, [FromRoute] int property_id, [FromBody] JsonPatchDocument <AssetPropertyPatch> _assetPropertyPatch)
        {
            try
            {
                //Get the asset instance
                var _assetInstance = _dbcontext.asset.Where(asset => asset.id == asset_id).FirstOrDefault();
                if (_assetInstance == null)
                {
                    return(NotFound("Asset not found"));
                }

                //get Property instance
                var _assetPropertyInstance = _dbcontext.asset_property.Where(property => property.id == property_id && property.asset.id == asset_id).FirstOrDefault();
                if (_assetPropertyInstance == null)
                {
                    return(NotFound("Asset property not found"));
                }

                // Map retrieved assetinstance to assetproperty  model with other properties (More or less with exactly same name)
                var assetPropertytoPatch = _mapper.Map <AssetPropertyPatch>(_assetPropertyInstance);

                // Apply assetinstance to ModelState
                _assetPropertyPatch.ApplyTo(assetPropertytoPatch, ModelState);


                if (_assetPropertyInstance.time_stamp < assetPropertytoPatch.time_stamp)
                {
                    // Assign entity changes to original entity retrieved from database
                    _mapper.Map(assetPropertytoPatch, _assetPropertyInstance);
                    // Say to entity framework that you have changes in assetpropety entity and it's modified
                    _dbcontext.Entry(_assetPropertyInstance).State = EntityState.Modified;
                    await _dbcontext.SaveChangesAsync();

                    return(Ok(_mapper.Map <AssetPropertyPatch>(_assetPropertyInstance)));
                }
                else
                {
                    return(BadRequest("Expect latest timestamp"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }