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 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 async Task <IActionResult> PutAssetNotes(long id, AssetNotes assetNotes) { if (id != assetNotes.IdNote) { return(BadRequest()); } _context.Entry(assetNotes).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AssetNotesExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutConfiguration(int id, Configuration configuration) { if (id != configuration.IdConfig) { return(BadRequest()); } _context.Entry(configuration).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ConfigurationExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutProvider(long id, Provider provider) { if (id != provider.ID) { return(BadRequest()); } _context.Entry(provider).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProviderExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutAcquisitionMethod(int id, AcquisitionMethod acquisitionMethod) { if (id != acquisitionMethod.ID) { return(BadRequest()); } _context.Entry(acquisitionMethod).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AcquisitionMethodExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task UpdateASMasterProductType(ASMasterProductType objADMasterProductType) { try { _Context.Entry(objADMasterProductType).State = EntityState.Modified; await _Context.SaveChangesAsync(); } catch (Exception ex) { throw new Exception(ex.Message); } }
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 async Task InsertASTransactionProductHistory(ASTransactionProductHistory objADTransactionProductHistory) { using (var transaction = _Context.Database.BeginTransaction()) { try { _Context.ASTransactionProductHistorys.Add(objADTransactionProductHistory); await _Context.SaveChangesAsync(); ASMasterProductChild objASMasterProductChild = _Context.ASMasterProductChilds.Find(objADTransactionProductHistory.MasterProductChildId); objASMasterProductChild.WarrantyExpiryDate = objADTransactionProductHistory.SubscriptionExpiryDate; _Context.Entry(objASMasterProductChild).State = EntityState.Modified; await _Context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw new Exception(ex.Message); } } }
public async Task UpdateASMasterAssetsAssignment(ASMasterAssetsAssignment objADMasterAssetsAssignment) { using (var transaction = _Context.Database.BeginTransaction()) { try { //Get MasterProductChild Detail var _MasterProductChild = _Context.ASMasterProductChilds.Find(objADMasterAssetsAssignment.MasterProductChildId); _MasterProductChild.MasterEmployeeId = objADMasterAssetsAssignment.MasterEmployeeId; _Context.Entry(_MasterProductChild).State = EntityState.Modified; await _Context.SaveChangesAsync(); ASMasterAssetsAssignment objASMasterAssetsAssignment = new ASMasterAssetsAssignment(); objASMasterAssetsAssignment.MasterAssetsAssignmentId = 0; //Assignment Date is passed through ManufacturingDate objASMasterAssetsAssignment.AssetsAssignmentDate = DateTime.Now; objASMasterAssetsAssignment.MasterProductChildId = _MasterProductChild.MasterProductChildId; objASMasterAssetsAssignment.MasterEmployeeId = _MasterProductChild.MasterEmployeeId; objASMasterAssetsAssignment.MasterLocationId = _MasterProductChild.MasterBranchId; objASMasterAssetsAssignment.IsActive = true; objASMasterAssetsAssignment.IsAssetsDeAssign = false; if (_MasterProductChild.MasterEmployeeId == 0) { objASMasterAssetsAssignment.IsActive = false; objASMasterAssetsAssignment.IsAssetsDeAssign = true; } objASMasterAssetsAssignment.EnterById = _MasterProductChild.EnterById; objASMasterAssetsAssignment.EnterDate = _MasterProductChild.EnterDate; objASMasterAssetsAssignment.ModifiedById = _MasterProductChild.ModifiedById; objASMasterAssetsAssignment.ModifiedDate = _MasterProductChild.ModifiedDate; //Check Whether record already exist or not long MasterAssetsAssignmentId; if (objADMasterAssetsAssignment.MasterAssetsAssignmentId == 0) { MasterAssetsAssignmentId = _Context.ASMasterAssetsAssignments.Where(a => a.MasterProductChildId == objADMasterAssetsAssignment.MasterProductChildId).Select(a => a.MasterAssetsAssignmentId).FirstOrDefault(); } else { MasterAssetsAssignmentId = objADMasterAssetsAssignment.MasterAssetsAssignmentId; } if (MasterAssetsAssignmentId == null || MasterAssetsAssignmentId == 0) { if (_MasterProductChild.MasterEmployeeId != null && _MasterProductChild.MasterEmployeeId > 0) { _Context.ASMasterAssetsAssignments.Add(objASMasterAssetsAssignment); await _Context.SaveChangesAsync(); } } else if (MasterAssetsAssignmentId != null && MasterAssetsAssignmentId > 0) { objASMasterAssetsAssignment.MasterAssetsAssignmentId = MasterAssetsAssignmentId; if (_MasterProductChild.MasterEmployeeId != null && _MasterProductChild.MasterEmployeeId > 0) { _Context.Entry(objASMasterAssetsAssignment).State = EntityState.Modified; await _Context.SaveChangesAsync(); } else { var ASMasterAssetsAssignmentNew = _Context.ASMasterAssetsAssignments.Find(MasterAssetsAssignmentId); _Context.ASMasterAssetsAssignments.Remove(ASMasterAssetsAssignmentNew); await _Context.SaveChangesAsync(); } } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw new Exception(ex.Message); } } }