public async Task <SimpleResult> AddWarehouse(WarehousePoco input) { await _context.Warehouses.AddAsync(input); await _context.SaveChangesAsync(); return(new SimpleResult { IsSuccess = true }); }
public async Task <SimpleResultPoco> EditInventory(InventoryPoco[] input) { await Task.Run(() => { _context.Inventories.UpdateRange(input); }); await _context.SaveChangesAsync(); return(new SimpleResultPoco { IsSuccess = true }); }
public async Task <SimpleResult> AddSite(SitePoco input) { var result = await _context.Sites.AddAsync(input); await _context.SaveChangesAsync(); return(new SimpleResult { IsSuccess = true, Id = input.Id }); }
public async Task <TimesheetResult> AddTimesheet(TimeSheetPoco poco) { var result = await _context.AddAsync(poco); await _context.SaveChangesAsync(); return(new TimesheetResult { Id = poco.Id, IsSuccess = true, TimesheetCode = poco.Code }); }
protected async Task <JsonResult> GenerateResult(object originalResult, IUserSettings userSettings) { dynamic result = new ExpandoObject(); result.data = originalResult; var user = await this.xatarisContext.Users.FindAsync(userSettings.UsersId); user.LastLoggedIn = DateTime.Now; await xatarisContext.SaveChangesAsync(); userSettings.CountLoggedIn = await xatarisContext.Users.Where(x => x.LastLoggedIn > DateTime.Now.AddHours(-1)).CountAsync(); try { result.localJwt = userSettings.LocalJwt.Token; result.modules = userSettings.Modules; result.logout = false; } catch { result.logout = true; } result.version = Assembly.GetAssembly(GetType()).GetName().Version.ToString(); return(Json(result)); }
public async Task <SimpleResult> AddSite(AddSiteViewModel input) { try { var site = await _context.Sites.FindAsync(input.Id); SimpleResult result; var poco = new SitePoco { Name = input.Name, Latitude = input.LatLng.Lat, Longitude = input.LatLng.Lng, Address = input.Address, Abbr = input.Abbr }; if (site != null) { site.Latitude = input.LatLng.Lat; site.Longitude = input.LatLng.Lng; site.Name = input.Name; site.Abbr = input.Abbr; site.Address = input.Address; _context.Entry(site).State = EntityState.Modified; await _context.SaveChangesAsync(); result = new SimpleResult { IsSuccess = true }; } else { result = await _domain.AddSite(poco); } return(result); } catch { return(new SimpleResult { IsSuccess = false }); } }
public async Task <SimpleResult> Add(OrderPoco input) { var poco = new OrderPoco { DateCreated = input.DateCreated, Deleted = false, Plumber = input.Plumber, Site = input.Site }; await _context.Orders.AddAsync(poco); await _context.SaveChangesAsync(); var selected = new List <OrderItemPoco>(); foreach (var s in input.OrderItems) { s.OrderId = Convert.ToInt32(poco.Id); selected.Add(new OrderItemPoco { Deleted = false, OrderId = s.OrderId, Quantity = s.Quantity, StockCode = s.StockCode, StockCost = s.StockCost, StockDescription = s.StockDescription }); } await _context.OrderItems.AddRangeAsync(selected); await _context.SaveChangesAsync(); return(new SimpleResult { IsSuccess = true }); }
public async Task UpdateUser(string userId) { var user = await _context.Users.FindAsync(userId); user.LastLoggedIn = DateTime.Now; _context.Entry(user).State = EntityState.Modified; var apiRequests = await _context.LookupValues.Where(x => x.LookupValuesId == (long)LookupValueEnum.ApiRequests).LastOrDefaultAsync(); if (apiRequests == null) { await _context.LookupValues.AddAsync(new LookupValue { LookupValuesId = (long)LookupValueEnum.ApiRequests, DataType = DataType.Integer, DataValue = "1", Updated = DateTime.Now }); } else { if (apiRequests.Updated.Date == DateTime.Today) { var lastApi = Convert.ToInt32(apiRequests.DataValue); lastApi = lastApi + 1; var newLookup = new LookupValue { DataType = DataType.Integer, DataValue = lastApi.ToString(), LookupValuesId = (long)LookupValueEnum.ApiRequests, Updated = DateTime.Now }; await _context.LookupValues.AddAsync(newLookup); } else { await _context.LookupValues.AddAsync(new LookupValue { LookupValuesId = (long)LookupValueEnum.ApiRequests, DataType = DataType.Integer, DataValue = "1", Updated = DateTime.Now }); } } await _context.SaveChangesAsync(); }
public async Task <SimpleResult> SaveMaterials(UploadInventoryViewModel input) { try { var warehouse = await _context.Warehouses.FindAsync(input.WarehousesId); var existingInventory = warehouse.Inventory; if (existingInventory != null) { _context.Inventories.RemoveRange(existingInventory); await _context.SaveChangesAsync(); } var newInventory = new List <InventoryPoco>(); foreach (var inv in input.Inventory) { var mat = _context.Materials.Where(x => x.StockCode == inv.StockCode).FirstOrDefault(); if (mat == null) { var material = new MaterialPoco { Cost = Convert.ToDecimal(inv.Cost, CultureInfo.InvariantCulture), StockCode = inv.StockCode, StockDescription = inv.StockDescription }; _context.Materials.Add(material); _context.SaveChanges(); var inventory = new InventoryPoco { DateAdded = DateTime.Now, DateModified = DateTime.Now, Deleted = false, MaterialId = material.Id, ModifiedBy = "", Quantity = Convert.ToDecimal(inv.Quantity, CultureInfo.InvariantCulture), WarehouseId = input.WarehousesId }; newInventory.Add(inventory); } else { var inventory = new InventoryPoco { DateAdded = DateTime.Now, DateModified = DateTime.Now, Deleted = false, MaterialId = mat.Id, ModifiedBy = "", Quantity = Convert.ToDecimal(inv.Quantity, CultureInfo.InvariantCulture), WarehouseId = input.WarehousesId }; newInventory.Add(inventory); } } await _context.AddRangeAsync(newInventory); await _context.SaveChangesAsync(); return(new SimpleResult { IsSuccess = true }); } catch { return(new SimpleResult { IsSuccess = false }); } }
public async Task <UserGroupPoco> AddGroup(UserGroupPoco input) { await _context.UserGroups.AddAsync(input); await _context.SaveChangesAsync(); return(input); }
public async Task <TimesheetResult> AddTimesheet(TimesheetViewModel input) { string code = ""; try { TimeSheetPoco poco = new TimeSheetPoco { AssistantTime = TimeSpan.Parse(input.SecondaryHours.ToString() + ":" + input.SecondaryMins.ToString()), OperatorTime = TimeSpan.Parse(input.PrimaryHours.ToString() + ":" + input.PrimaryMins.ToString()), DateCreated = DateTime.Now, Deleted = false, Code = "", Description = input.Description, DetailedPoint = input.DetailedPoint, OriginalQuote = input.OriginalQuote, QuoteNo = input.QuoteNumber, SheetStatus = input.Status, SINumber = input.SiNumber, SiteId = input.Site, SpecificLocation = input.SpecificLocation, UsersId = input.PrimaryTechnician }; var site = await _context.Sites.FindAsync(poco.SiteId); var lastCode = await _context.TimeSheets.OrderByDescending(x => x.DateCreated).FirstOrDefaultAsync(); if (lastCode != null) { int suffix = Convert.ToInt32(lastCode.Code.Split("-")[2]); StringBuilder newPrefix = new StringBuilder(); StringBuilder newSuffix = new StringBuilder(); if (suffix == 9999) { newSuffix.Append("0000"); char firstPrefix = lastCode.Code.Split("-")[0][0]; char lastPrefix = lastCode.Code.Split("-")[0][1]; if (lastPrefix == 'Z') { lastPrefix = 'A'; int index = alphabet.IndexOf(firstPrefix); firstPrefix = alphabet[index + 1]; } else { int index = alphabet.IndexOf(lastPrefix); lastPrefix = alphabet[index + 1]; } newPrefix = new StringBuilder(); newPrefix.Append(firstPrefix); newPrefix.Append(lastPrefix); } else { suffix += 1; newSuffix.Append(string.Format("{0:D4}", suffix)); newPrefix.Append(lastCode.Code.Split("-")[1]); } poco.Code = site.Abbr + "-" + newPrefix.ToString() + "-" + newSuffix.ToString(); } else { poco.Code = site.Abbr + "-" + "AA-0001"; } code = poco.Code; await _timesheet.AddTimesheet(poco); await _context.SaveChangesAsync(); //foreach (var email in _configuration["clients:plumbery:emails"].Split("::")) //{ // await _emailSender.SendEmailAsync(email, "Timesheet " + poco.Code + " submitted", ""); //} return(new TimesheetResult { IsSuccess = true, TimesheetCode = poco.Code }); } catch (Exception ex) { return(new TimesheetResult { ErrorMessage = ex.Message, IsSuccess = true, TimesheetCode = code }); } }