Ejemplo n.º 1
0
        public ServiceResult GetAttributes()
        {
            if (CurrentUser == null)
            {
                return(ServiceResponse.Error("You must be logged in to access this function."));
            }

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

            DataFilter     filter     = this.GetFilter(Request);
            List <dynamic> Attributes = (List <dynamic>)AttributeManager.GetAttributes(CurrentUser.AccountUUID, ref filter).Cast <dynamic>().ToList();

            Attributes = Attributes.Filter(ref filter);
            return(ServiceResponse.OK("", Attributes, filter.TotalRecordCount));
        }
Ejemplo n.º 2
0
        public ServiceResult DeleteAttribute(string UUID)//todo bookmark latest test this.
        {
            if (string.IsNullOrWhiteSpace(UUID))
            {
                return(ServiceResponse.Error("No id was sent."));
            }

            if (CurrentUser == null)
            {
                return(ServiceResponse.Error("You must be logged in to access this function."));
            }

            AttributeManager atm = new AttributeManager(Globals.DBConnectionKey, this.GetAuthToken(Request));
            var res = atm.Get(UUID);

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

            var attribute = res.Result as TMG.Attribute;

            if (attribute.ValueType.EqualsIgnoreCase("ImagePath") == false)
            {
                return(atm.Delete(attribute, true));
            }

            string root = System.Web.HttpContext.Current.Server.MapPath("~/Content/Uploads/" + this.CurrentUser.UUID);

            string          fileName   = attribute.Image.GetFileNameFromUrl(); //todo get folder and file from attribute.Image => https://localhost:44318/Content/Uploads/8ac0adc1e7154afda15069c822d68d6d/20190226_082504appicon.png
            string          pathToFile = Path.Combine(root, fileName);
            DocumentManager dm         = new DocumentManager(Globals.DBConnectionKey, this.GetAuthToken(Request));

            if (dm.DeleteFile(attribute, pathToFile).Code != 200)
            {
                return(ServiceResponse.Error("Failed to delete file " + fileName));
            }
            DataFilter           filter     = this.GetFilter(Request);
            List <TMG.Attribute> attributes = atm.GetAttributes(this.CurrentUser.AccountUUID, ref filter)
                                              .Where(w => w.UUIDType.EqualsIgnoreCase("ImagePath") &&
                                                     w.Value == attribute.UUID &&
                                                     w.Image.Contains(fileName)).ToList();

            // Update attributes that are using this image.
            foreach (TMG.Attribute att in attributes)
            {
                // if (am.DeleteSetting(setting.UUID).Code != 200)
                //  return ServiceResponse.Error("Failed to delete image setting for file " + fileName);
                att.Image = "/assets/img/blankprofile.png"; // todo change image. Monetize?
            }

            var res1 = atm.Delete(attribute, true);

            ProfileManager profileManager = new ProfileManager(Globals.DBConnectionKey, Request.Headers.Authorization?.Parameter);
            var            tmp            = profileManager.GetProfile(CurrentUser.UUID, CurrentUser.AccountUUID, true);

            if (tmp.Code != 200)
            {
                return(tmp);
            }
            GreenWerx.Models.Membership.Profile profile = (Profile)tmp.Result;

            if (profile.Image.Contains(fileName))
            {
                profile.Image = "/assets/img/blankprofile.png";
            }

            return(profileManager.UpdateProfile(profile));
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
        public ServiceResult GetProductDetails(string uuid, string type)
        {
            if (string.IsNullOrWhiteSpace(uuid))
            {
                return(ServiceResponse.Error("You must provide a name for the strain."));
            }


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

            if (type.EqualsIgnoreCase("PRODUCT"))
            {
                ProductManager productManager = new ProductManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);
                Product        p = (Product)productManager.GetBy(uuid);

                if (p == null)
                {
                    return(ServiceResponse.Error("Product could not be located for the uuid " + uuid));
                }

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


            AccountManager am = new AccountManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);
            Account        a  = (Account)am.GetBy(ManufacturerUUID);

            AttributeManager     atm        = new AttributeManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);
            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,
                    Id          = a.Id,
                    Private     = a.Private,
                    Status      = a.Status,
                    Value       = a.Name,
                    ValueType   = "string"
                });
            }

            #region plant related info
            StrainManager pm = new StrainManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);
            Strain        s  = (Strain)pm.GetBy(strainUUID);
            if (s != null)
            {
                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,
                    Id          = s.Id,
                    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,
                    Id          = s.Id,
                    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,
                    Id          = s.Id,
                    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,
                        Id          = s.Id,
                        Private     = s.Private,
                        Status      = s.Status,
                        Value       = s.Generation,
                        ValueType   = "string"
                    });
                }

                CategoryManager cm = new CategoryManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);
                Category        c  = (Category)cm.GetBy(s.CategoryUUID);
                if (c != null)
                {
                    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,
                        Id          = c.Id,
                        Private     = c.Private,
                        Status      = c.Status,
                        Value       = c.Name,
                        ValueType   = "string"
                    });
                }
            }
            #endregion

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