public ServiceResult Delete(Strain s) { if (s == null || string.IsNullOrWhiteSpace(s.UUID)) { return(ServiceResponse.Error("Invalid account was sent.")); } StrainManager strainManager = new StrainManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter); return(strainManager.Delete(s)); }
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)); }
public ServiceResult Delete(Strain s) { if (s == null || string.IsNullOrWhiteSpace(s.UUID)) { return(ServiceResponse.Error("Invalid account was sent.")); } StrainManager strainManager = new StrainManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); return(strainManager.Delete(s)); }
public ServiceResult GetStrains() { if (CurrentUser == null) { return(ServiceResponse.Error("You must be logged in to access this function.")); } StrainManager strainManager = new StrainManager(Globals.DBConnectionKey, this.GetAuthToken(Request)); List <dynamic> Strains = (List <dynamic>)strainManager.GetStrains(CurrentUser.AccountUUID, false, true).Cast <dynamic>().ToList(); DataFilter filter = this.GetFilter(Request); Strains = Strains.Filter(ref filter); return(ServiceResponse.OK("", Strains, filter.TotalRecordCount)); }
public ServiceResult GetStrains(string filter = "") { if (CurrentUser == null) { return(ServiceResponse.Error("You must be logged in to access this function.")); } StrainManager strainManager = new StrainManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter); List <dynamic> Strains = (List <dynamic>)strainManager.GetStrains(CurrentUser.AccountUUID, false, true).Cast <dynamic>().ToList(); int count; DataFilter tmpFilter = this.GetFilter(filter); Strains = FilterEx.FilterInput(Strains, tmpFilter, out count); return(ServiceResponse.OK("", Strains, count)); }
public ServiceResult Delete(string uuid) { if (string.IsNullOrWhiteSpace(uuid)) { return(ServiceResponse.Error("Invalid id was sent.")); } StrainManager strainManager = new StrainManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter); Strain fa = (Strain)strainManager.GetBy(uuid); if (fa == null) { return(ServiceResponse.Error("Could not find strain.")); } return(strainManager.Delete(fa)); }
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, Request.Headers?.Authorization?.Parameter); Strain s = (Strain)strainManager.GetBy(uuid); if (s == null) { return(ServiceResponse.Error("Strain could not be located for the name " + uuid)); } return(ServiceResponse.OK("", s)); }
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, this.GetAuthToken(Request)); List <Strain> s = strainManager.Search(name); if (s == null || s.Count == 0) { return(ServiceResponse.Error("Strain could not be located for the name " + name)); } return(ServiceResponse.OK("", s)); }
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, Request.Headers?.Authorization?.Parameter); var dbS = (Strain)strainManager.GetBy(form.UUID); if (dbS == null) { return(ServiceResponse.Error("Strain was not found.")); } 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)); }
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)); }
public ServiceResult Insert(StrainForm s) { if (s == null || string.IsNullOrWhiteSpace(s.Name)) { return(ServiceResponse.Error("Invalid Strain sent to server.")); } if (!string.IsNullOrWhiteSpace(s.UUID)) { return(this.Update(s)); } if (s.IndicaPercent + s.SativaPercent > 100) { return(ServiceResponse.Error("Variety percentages cannot be greater than 100%.")); } string authToken = Request.Headers?.Authorization?.Parameter; UserSession us = SessionManager.GetSession(authToken); if (us == null) { return(ServiceResponse.Error("You must be logged in to access this function.")); } if (us.Captcha?.ToUpper() != s.Captcha?.ToUpper()) { return(ServiceResponse.Error("Invalid code.")); } if (string.IsNullOrWhiteSpace(us.UserData)) { return(ServiceResponse.Error("Couldn't retrieve user data.")); } if (CurrentUser == null) { return(ServiceResponse.Error("You must be logged in to access this function.")); } if (string.IsNullOrWhiteSpace(s.AccountUUID) || s.AccountUUID == SystemFlag.Default.Account) { s.AccountUUID = CurrentUser.AccountUUID; } if (string.IsNullOrWhiteSpace(s.CreatedBy)) { s.CreatedBy = CurrentUser.UUID; } if (s.DateCreated == DateTime.MinValue) { s.DateCreated = DateTime.UtcNow; } AccountManager accountManager = new AccountManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter); Account a = accountManager.AddAccountFromStrain(s); if (a != null && string.IsNullOrWhiteSpace(s.BreederUUID)) { s.BreederUUID = a.UUID; } #region Convert to Strain from StrainView because entity frameworks doesn't recognize casting. var config = new MapperConfiguration(cfg => { cfg.CreateMap <StrainForm, Strain>(); }); IMapper mapper = config.CreateMapper(); var dest = mapper.Map <StrainForm, Strain>(s); #endregion StrainManager strainManager = new StrainManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter); return(strainManager.Insert(dest, true)); }
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)); }
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)); }