示例#1
0
        public ServiceResult GetBy(string uuid)
        {
            if (string.IsNullOrWhiteSpace(uuid))
            {
                return(ServiceResponse.Error("You must provide a uuid for the strain."));
            }

            StrainManager strainManager = new StrainManager(Globals.DBConnectionKey, this.GetAuthToken(Request));

            return(strainManager.Get(uuid));
        }
示例#2
0
        public ServiceResult Get(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return(ServiceResponse.Error("You must provide a name for the strain."));
            }

            StrainManager strainManager = new StrainManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);

            Strain s = (Strain)strainManager.Get(name);

            if (s == null)
            {
                return(ServiceResponse.Error("Strain could not be located for the name " + name));
            }

            return(ServiceResponse.OK("", s));
        }
示例#3
0
        public ServiceResult Delete(string uuid)
        {
            if (string.IsNullOrWhiteSpace(uuid))
            {
                return(ServiceResponse.Error("Invalid id was sent."));
            }

            StrainManager strainManager = new StrainManager(Globals.DBConnectionKey, this.GetAuthToken(Request));
            var           res           = strainManager.Get(uuid);

            if (res.Code != 200)
            {
                return(res);
            }

            Strain fa = (Strain)res.Result;

            return(strainManager.Delete(fa));
        }
示例#4
0
        public ServiceResult Update(Strain form)
        {
            if (form == null)
            {
                return(ServiceResponse.Error("Invalid Strain sent to server."));
            }

            if (form.IndicaPercent + form.SativaPercent > 100)
            {
                return(ServiceResponse.Error("Variety percentages cannot be greater than 100%."));
            }

            StrainManager strainManager = new StrainManager(Globals.DBConnectionKey, this.GetAuthToken(Request));

            var res = strainManager.Get(form.UUID);

            if (res.Code != 200)
            {
                return(res);
            }
            var dbS = (Strain)res.Result;

            if (dbS.DateCreated == DateTime.MinValue)
            {
                dbS.DateCreated = DateTime.UtcNow;
            }

            dbS.Name          = form.Name;
            dbS.BreederUUID   = form.BreederUUID;
            dbS.CategoryUUID  = form.CategoryUUID;
            dbS.HarvestTime   = form.HarvestTime;
            dbS.IndicaPercent = form.IndicaPercent;
            dbS.SativaPercent = form.SativaPercent;
            dbS.AutoFlowering = form.AutoFlowering;
            dbS.Generation    = form.Generation;
            dbS.Lineage       = form.Lineage;
            //below are not on Strain.cshtml form
            dbS.Deleted   = form.Deleted;
            dbS.Status    = form.Status;
            dbS.SortOrder = form.SortOrder;
            return(strainManager.Update(dbS));
        }
示例#5
0
        public ServiceResult GetProductDetails(string uuid, string type)
        {
            if (string.IsNullOrWhiteSpace(uuid))
            {
                return(ServiceResponse.Error("You must provide an id for the product."));
            }

            string refUUID          = "";
            string refType          = "";
            string refAccount       = "";
            string ManufacturerUUID = "";
            string strainUUID       = "";

            if (type.EqualsIgnoreCase("PRODUCT"))
            {
                ProductManager productManager = new ProductManager(Globals.DBConnectionKey, this.GetAuthToken(Request));
                var            res1           = productManager.Get(uuid);
                if (res1.Code != 200)
                {
                    return(res1);
                }

                Product p = (Product)res1.Result;

                refUUID          = p.UUID;
                refType          = p.UUIDType;
                refAccount       = p.AccountUUID;
                ManufacturerUUID = p.ManufacturerUUID;
                strainUUID       = p.StrainUUID;
            }

            AccountManager am   = new AccountManager(Globals.DBConnectionKey, this.GetAuthToken(Request));
            var            resa = am.Get(ManufacturerUUID);

            if (resa.Code != 200)
            {
                return(resa);
            }

            Account a = (Account)resa.Result;

            AttributeManager     atm        = new AttributeManager(Globals.DBConnectionKey, this.GetAuthToken(Request));
            List <TMG.Attribute> attributes = atm.GetAttributes(refUUID, refType, refAccount)?.Where(w => w.Deleted == false).ToList();

            if (attributes == null)
            {
                attributes = new List <TMG.Attribute>();
            }
            if (a != null)
            {
                attributes.Add(new TMG.Attribute()
                {
                    Name        = "Manufacturer",
                    AccountUUID = a.AccountUUID,
                    UUIDType    = a.UUIDType,
                    Active      = a.Active,
                    CreatedBy   = a.CreatedBy,
                    DateCreated = a.DateCreated,
                    Deleted     = a.Deleted,
                    Private     = a.Private,
                    Status      = a.Status,
                    Value       = a.Name,
                    ValueType   = "string"
                });
            }

            #region plant related info

            StrainManager pm  = new StrainManager(Globals.DBConnectionKey, this.GetAuthToken(Request));
            var           res = pm.Get(strainUUID);
            if (res.Code != 200)
            {
                return(res);
            }

            Strain s = (Strain)res.Result;
            attributes.Add(new TMG.Attribute()
            {
                Name        = "Strain Name",
                AccountUUID = s.AccountUUID,
                UUIDType    = s.UUIDType,
                Active      = s.Active,
                CreatedBy   = s.CreatedBy,
                DateCreated = s.DateCreated,
                Deleted     = s.Deleted,
                Private     = s.Private,
                Status      = s.Status,
                Value       = s.Name,
                ValueType   = "string"
            });

            attributes.Add(new TMG.Attribute()
            {
                Name        = "Indica Percent",
                AccountUUID = s.AccountUUID,
                UUIDType    = s.UUIDType,
                Active      = s.Active,
                CreatedBy   = s.CreatedBy,
                DateCreated = s.DateCreated,
                Deleted     = s.Deleted,
                Private     = s.Private,
                Status      = s.Status,
                Value       = s.IndicaPercent.ToString(),
                ValueType   = "number"
            });

            attributes.Add(new TMG.Attribute()
            {
                Name        = "Sativa Percent",
                AccountUUID = s.AccountUUID,
                UUIDType    = s.UUIDType,
                Active      = s.Active,
                CreatedBy   = s.CreatedBy,
                DateCreated = s.DateCreated,
                Deleted     = s.Deleted,
                Private     = s.Private,
                Status      = s.Status,
                Value       = s.SativaPercent.ToString(),
                ValueType   = "number"
            });

            if (!string.IsNullOrWhiteSpace(s.Generation))
            {
                attributes.Add(new TMG.Attribute()
                {
                    Name        = "Generation",
                    AccountUUID = s.AccountUUID,
                    UUIDType    = s.UUIDType,
                    Active      = s.Active,
                    CreatedBy   = s.CreatedBy,
                    DateCreated = s.DateCreated,
                    Deleted     = s.Deleted,
                    Private     = s.Private,
                    Status      = s.Status,
                    Value       = s.Generation,
                    ValueType   = "string"
                });
            }

            CategoryManager cm   = new CategoryManager(Globals.DBConnectionKey, this.GetAuthToken(Request));
            var             resc = cm.Get(s.CategoryUUID);
            if (resc.Code != 200)
            {
                return(resc);
            }

            Category c = (Category)resc.Result;
            attributes.Add(new TMG.Attribute()
            {
                Name        = "Variety",
                AccountUUID = c.AccountUUID,
                UUIDType    = c.UUIDType,
                Active      = c.Active,
                CreatedBy   = c.CreatedBy,
                DateCreated = c.DateCreated,
                Deleted     = c.Deleted,
                Private     = c.Private,
                Status      = c.Status,
                Value       = c.Name,
                ValueType   = "string"
            });

            #endregion plant related info

            return(ServiceResponse.OK("", attributes));
        }