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 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
                        });
                    }
                }
            }
        }
Beispiel #3
0
        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> 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
                        });
                    }
                }
            }
        }