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 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 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 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)); }