public CreateOperationResult CreateFavoriteVendor(FavoriteVendorDTO dto) { using (var dbContext = new GrowFlowContext()) { using (var service = ComplianceService.Create(dbContext, account)) { try { var result = service.CreateFavoriteVendor( account, dto.VendorId, dto.Notes); return(new CreateOperationResult() { Success = true, Data = result }); } catch (Exception e) { return(new CreateOperationResult() { Success = false, Exception = e.Message }); } } } }
public List <VendorDTO> GetVendors(int accountId) { List <VendorDTO> vendors = new List <VendorDTO>(); using (var dbContext = new GrowFlowContext()) { using (var service = ComplianceService.Create(dbContext, account)) { vendors = service.GetVendors() .Select(v => new VendorDTO { Id = v.Id, Name = v.Name, Address = new AddressDTO() { Line1 = v.Address.Line1, Line2 = v.Address.Line2, Line3 = v.Address.Line3, City = v.Address.City, Country = v.Address.Country, PostalCode = v.Address.PostalCode, Region = v.Address.Region }, Type = v.Type }).ToList(); return(vendors); } } }
public List <EmployeeDTO> GetEmployees(int accountId) { List <EmployeeDTO> employees = new List <EmployeeDTO>(); using (var dbContext = new GrowFlowContext()) { using (var service = ComplianceService.Create(dbContext, account)) { employees = service.GetEmployees() .Select(r => new EmployeeDTO { Id = r.Id, FirstName = r.FirstName, LastName = r.LastName, DateOfBirth = r.DateOfBirth, DateOfHire = r.DateOfHire, SocialSecurity = r.SocialSecurity, EmployeeNum = r.EmployeeNum, VehicleId = r.Vehicle?.Id }).ToList(); return(employees); } } }
public OperationResult DeleteVendor(int vendorId) { using (var dbContext = new GrowFlowContext()) { using (var service = ComplianceService.Create(dbContext, account)) { try { var result = service.DeleteFavoriteVendor(account, vendorId); return(new CreateOperationResult() { Success = result }); } catch (Exception e) { return(new CreateOperationResult() { Success = false, Exception = e.Message }); } } } }
public async Task <OperationResult> DeleteStrain(int strainId) { using (var dbContext = new GrowFlowContext()) { using (var service = ComplianceService.Create(dbContext, account)) { try { var strain = dbContext.Strains.Single(s => s.Id == strainId && s.AccountId == account.Id); dbContext.Strains.Attach(strain); dbContext.Strains.Remove(strain); dbContext.SaveChanges(); return(new CreateOperationResult() { Success = true }); } catch (Exception e) { return(new CreateOperationResult() { Success = false, Exception = e.Message }); } } } }
public List <VehicleDTO> GetVehicles(int accountId) { List <VehicleDTO> vehicles = new List <VehicleDTO>(); using (var dbContext = new GrowFlowContext()) { using (var service = ComplianceService.Create(dbContext, account)) { vehicles = service.GetVehicles() .Select(r => new VehicleDTO { Id = r.Id, Nickname = r.Nickname, Color = r.Color, Make = r.Make, Model = r.Model, Year = r.Year.ToString(), PlateNum = r.Plate, Vin = r.Vin }).ToList(); return(vehicles); } } }
public async Task <CreateOperationResult> CreateVehicle(CreateVehicleDTO dto) { using (var dbContext = new GrowFlowContext()) { using (var service = ComplianceService.Create(dbContext, account)) { try { var result = await service.CreateVehicleAsync( account, dto.Nickname, dto.Color, dto.Make, dto.Model, int.Parse(dto.Year), dto.PlateNum, dto.Vin); return(new CreateOperationResult() { Success = true, Data = result }); } catch (Exception e) { return(new CreateOperationResult() { Success = false, Exception = e.Message }); } } } }
public async Task <CreateOperationResult> CreateEmployee(CreateEmployeeDTO dto) { using (var dbContext = new GrowFlowContext()) { using (var service = ComplianceService.Create(dbContext, account)) { try { var result = await service.CreateEmployeeAsync( account, dto.FirstName, dto.LastName, dto.DateOfBirth, dto.DateOfHire, dto.SocialSecurity, dto.EmployeeNum, dto.VehicleId); return(new CreateOperationResult() { Success = true, Data = result }); } catch (Exception e) { return(new CreateOperationResult() { Success = false, Exception = e.Message }); } } } }
public async Task <CreateOperationResult> CreateProduct(Product Product) { using (var dbContext = new GrowFlowContext()) { using (var service = ComplianceService.Create(dbContext, account)) { try { var getProduct = dbContext.Products.FirstOrDefault(s => s.AccountId == account.Id && s.Name.ToLower() == Product.Name.ToLower()); if (getProduct == null) { Product.AccountId = account.Id; dbContext.Products.Add(Product); dbContext.SaveChanges(); } return(new CreateOperationResult() { Success = true, Data = Product }); } catch (Exception e) { return(new CreateOperationResult() { Success = false, Exception = e.Message }); } } } }
public async Task <CreateOperationResult> CreateStrain(Strain strain) { using (var dbContext = new GrowFlowContext()) { using (var service = ComplianceService.Create(dbContext, account)) { try { var getstrain = dbContext.Strains.FirstOrDefault(s => s.AccountId == account.Id && s.Name.ToLower() == strain.Name.ToLower()); if (getstrain == null) { dbContext.Strains.Add(strain); dbContext.SaveChanges(); } return(new CreateOperationResult() { Success = true, Data = strain }); } catch (Exception e) { return(new CreateOperationResult() { Success = false, Exception = e.Message }); } } } }
public async Task <OperationResult> DeleteVehicle(int vehicleId) { using (var dbContext = new GrowFlowContext()) { using (var service = ComplianceService.Create(dbContext, account)) { try { var result = await service.DeleteVehicleAsync(account, vehicleId); return(new CreateOperationResult() { Success = result }); } catch (Exception e) { return(new CreateOperationResult() { Success = false, Exception = e.Message }); } } } }
public List <Strain> GetStrain(int accountId) { using (var dbContext = new GrowFlowContext()) { using (var service = ComplianceService.Create(dbContext, account)) { var strains = dbContext.Strains.Where(s => s.AccountId == account.Id); return(strains.ToList()); } } }
public List <Product> GetProduct(int accountId) { using (var dbContext = new GrowFlowContext()) { using (var service = ComplianceService.Create(dbContext, account)) { var Products = dbContext.Products.Where(s => s.AccountId == account.Id); return(Products.ToList()); } } }
public List <Brand> GetBrand(int accountId) { using (var dbContext = new GrowFlowContext()) { using (var service = ComplianceService.Create(dbContext, account)) { var Brands = dbContext.Brands.Where(s => s.AccountId == account.Id); return(Brands.ToList()); } } }
public DeletableDTO IsStrainDeletable(int strainId) { using (var dbContext = new GrowFlowContext()) { using (var service = ComplianceService.Create(dbContext, account)) { bool isDeletable = service.DoesStrainContainInventory(account, strainId); return(new DeletableDTO { IsDeletable = isDeletable, Message = "Please remove all inventory from this strain before deleting." }); } } }
public DeletableDTO IsProductDeletable(int id) { using (var dbContext = new GrowFlowContext()) { using (var service = ComplianceService.Create(dbContext, account)) { // bool isDeletable = service.DoesProductContainInventory(account, ProductId); return(new DeletableDTO { IsDeletable = false, Message = "Please remove all inventory from this Product before deleting." }); } } }
public async Task <CreateOperationResult> EditStrain(int strainId, Strain strain) { using (var dbContext = new GrowFlowContext()) { using (var service = ComplianceService.Create(dbContext, account)) { Strain facility = dbContext.Set <Strain>().AsNoTracking() .FirstOrDefault(s => s.AccountId == account.Id && s.Id == strainId); if (facility == null) { return(new CreateOperationResult() { Success = false, Exception = "Unable to edit strain. No facility location exists for this account." }); } try { // strain.Daysinflower = .Daysinflower; dbContext.Strains.Attach(strain); var entry = dbContext.Entry(strain); entry.State = EntityState.Modified; dbContext.SaveChanges(); return(new CreateOperationResult() { Success = true, Data = strain }); } catch (Exception e) { return(new CreateOperationResult() { Success = false, Exception = e.Message }); } } } }
public async Task <CreateOperationResult> CreateRoom(CreateRoomDTO dto) { using (var dbContext = new GrowFlowContext()) { using (var service = ComplianceService.Create(dbContext, account)) { Site facility = dbContext.Set <Site>().AsNoTracking() .SingleOrDefault(s => s.AccountId == account.Id && s.Type == SiteType.Facility); if (facility == null) { return(new CreateOperationResult() { Success = false, Exception = "Unable to create room. No facility location exists for this account." }); } try { var result = await service.CreateRoomAsync( account, facility, dto.Name, dto.Type, dto.Notes); return(new CreateOperationResult() { Success = true, Data = result }); } catch (Exception e) { return(new CreateOperationResult() { Success = false, Exception = e.Message }); } } } }
public List <FavoriteVendorDTO> GetFavoriteVendors(int accountId) { List <FavoriteVendorDTO> FavoriteVendors = new List <FavoriteVendorDTO>(); using (var dbContext = new GrowFlowContext()) { using (var service = ComplianceService.Create(dbContext, account)) { FavoriteVendors = service.GetFavoriteVendors() .Select(v => new FavoriteVendorDTO { Id = v.Id, Notes = v.Notes, VendorId = v.Vendor.Id }).ToList(); return(FavoriteVendors); } } }
public List <RoomDTO> GetRooms(int accountId) { List <RoomDTO> rooms = new List <RoomDTO>(); using (var dbContext = new GrowFlowContext()) { using (var service = ComplianceService.Create(dbContext, account)) { rooms = service.GetRooms() .Where(r => !string.IsNullOrEmpty(r.Name)) .Select(r => new RoomDTO { Id = r.Id, Name = r.Name, Type = r.Stage.ToRoomType(), Notes = r.Notes, IsPlant = r.IsPlant }).ToList(); return(rooms); } } }
public ActionResult Get() { using (var dbContext = new GrowFlowContext()) { using (var service = ComplianceService.Create(dbContext, account)) { var inventory = dbContext.Inventory .Include(i => i.Strain) .Include(i => i.Site) .Include(i => i.InventoryQaChecks) .Include(i => i.InventoryQaSamples) .Where(c => !c.IsDeleted && c.AccountId == account.Id) .ToList(); var inventoryDTO = new List <InventoryDTO>(); inventoryDTO.AddRange( inventory.Select(i => { var qaCheck = i.InventoryQaChecks.FirstOrDefault(); var CBD = ""; var THC = ""; if (qaCheck != null) { CBD = qaCheck.CBD; THC = qaCheck.THC; } string QAResult = "Not Implemented"; /* * if (i.InventoryQaSamples.Count > 0) * { * QAResult = i.InventoryQaSamples.Result.ToString(); * } * if (!string.IsNullOrEmpty(QAResult)) * { * if (QAResult.ToString() == "-1") * { * QAResult = "Fail"; * } * else if (QAResult.ToString() == "0") * { * QAResult = "Waiting"; * } * else if (QAResult.ToString() == "1") * { * QAResult = "Pass"; * } * } * else * { * QAResult = "-"; * } */ var dto = new InventoryDTO() { CBD = CBD, ComplianceId = i.ComplianceId, Description = i.ProductName, Available = i.RemainingQuantity, QAResult = QAResult, THC = THC, Type = i.Type, RoomName = i.Site != null ? i.Site.Name : " - ", Size = i.UsableWeight.ToString(), Strain = i.Strain != null ? i.Strain.Name : " - " }; return(dto); })); return(JsonObject(inventoryDTO)); } } }