public void updateDepreciation() { try { var assets = _context.Assets.Include(x => x.Depreciation).Where(x => x.Status == 1); foreach (Asset a in assets) { if (!string.IsNullOrEmpty(a.Depreciation.Frequency)) { if (a.CurrentPrice > 0 || a.AcquisitionDate < a.AcquisitionDate.AddYears(int.Parse(a.Depreciation.Frequency))) { var diff = (DateTime.Now - a.AcquisitionDate).TotalDays; var daily = a.Depreciation.Percentage / 30; a.CurrentPrice = a.PurchasePrice - (a.PurchasePrice * ((daily * diff) / 100)); _context.Entry(a).State = EntityState.Modified; } } } _context.SaveChanges(); } catch (Exception ex) { throw; } }
public ActionResult <User> Login(long id, User user) { var _user = _context.Users.FirstOrDefault(x => x.Email == user.Email && x.Password == user.Password && x.IsActive); var ip = Request.HttpContext.Connection.RemoteIpAddress.ToString(); var client = Request.Headers["User-Agent"].ToString(); if (_user != null) { var tk = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes( string.Format("{0}:{1}:{2}:{3}", user.Id, ip, client, DateTime.Now))); var token = new Token() { Content = tk, IsActive = true, Created = DateTime.Now, Expire = DateTime.Now.AddMinutes(30), Type = _user.Type }; _user.LastLogin = DateTime.UtcNow; _context.Entry(_user).State = EntityState.Modified; _context.Tokens.Add(token); _context.SaveChanges(); _user.Token = token.Content; return(_user); deleteInactiveTokens(); } else { return(new UnauthorizedResult()); } }
public static void Add(AssetType newAsset) { var context = new AssetsContext(); context.AssetTypes.Add(newAsset); context.SaveChanges(); }
// add a new asset public static void AddNewAsset(Asset asset) { var context = new AssetsContext(); context.Assets.Add(asset); context.SaveChanges(); }
//method that adds a new asset type to the database public static void Add(AssetType assetType) { var context = new AssetsContext(); context.AssetTypes.Add(assetType); //add the asset to the context context.SaveChanges(); //save changes to the database }
// add new type public static void AddNewType(AssetType type) { var context = new AssetsContext(); context.AssetTypes.Add(type); context.SaveChanges(); }
public static void Add(AssetType assetType) { AssetsContext context = new AssetsContext(); context.AssetTypes.Add(assetType); context.SaveChanges(); }
public static void update(AssetType assetType) { var context = new AssetsContext(); var originalAssetType = context.AssetTypes.Find(assetType.Id); originalAssetType.Name = assetType.Name; context.SaveChanges(); }
public static void UpdateAssetType(AssetType newAssetType) { var context = new AssetsContext(); var assetType = context.AssetTypes.SingleOrDefault(a => a.Id == newAssetType.Id); assetType.Name = newAssetType.Name; context.SaveChanges(); }
// get type by id public static void Update(AssetType newType) { var context = new AssetsContext(); var old = context.AssetTypes.Include(at => at.Assets). SingleOrDefault(at => at.Id == newType.Id); old.Name = newType.Name; context.SaveChanges(); }
public static void Update(Asset asset) { var context = new AssetsContext(); var originalAsset = context.Assets.Find(asset.Id); originalAsset.Manufacturer = asset.Manufacturer; originalAsset.Model = asset.Model; originalAsset.SerialNumber = asset.SerialNumber; originalAsset.TagNumber = asset.TagNumber; originalAsset.Description = asset.Description; originalAsset.AssetType = asset.AssetType; context.SaveChanges(); }
public static void UpdateAsset(Asset newAsset) { var context = new AssetsContext(); // Find the domain entity with this context, that has the same Id as the entity pass in var oldAsset = context.Assets.SingleOrDefault(a => a.Id == newAsset.Id); // Assign properties from newAsset to properties in oldAsset oldAsset.TagNumber = newAsset.TagNumber; oldAsset.AssetTypeId = newAsset.AssetTypeId; oldAsset.Manufacturer = newAsset.Manufacturer; oldAsset.Model = newAsset.Model; oldAsset.Description = newAsset.Description; oldAsset.SerialNumber = newAsset.SerialNumber; context.SaveChanges(); }
private void setReponsibleByLocation(Location location, bool one = true, bool two = true) { var assets = _context.Assets .Include(x => x.Responsible).AsNoTracking() .Include(x => x.Responsible2).AsNoTracking() .Include(x => x.Location) .Where(x => x.Location.ID == location.ID && x.Status == 1).ToList(); foreach (var asset in assets) { if (one) { asset.Responsible = location.Responsible1; } if (two) { asset.Responsible2 = location.Responsible2; } _context.Entry(asset).State = EntityState.Modified; } _context.SaveChanges(); }
public void Add(AssetType assetType) { //var context = new AssetsContext(); _context.AssetTypes.Add(assetType); _context.SaveChanges(); }
public void Add(Manufacturer manufacturer) { //var context = new AssetsContext(); _context.Manufacturers.Add(manufacturer); _context.SaveChanges(); }
public void Add(Asset asset) { //var context = new AssetsContext(); _context.Assets.Add(asset); _context.SaveChanges(); }