Пример #1
0
 public LaborItemApiType(LaborItem li)
 {
     id     = li.Id;
     Name   = li.Name;
     pph    = li.pph;
     ppp    = li.ppp;
     Vendor = li.Vendor.Name;
 }
Пример #2
0
        public string GetLaborItem(int id)
        {
            LaborItem laborItem = db.LaborTable.Find(id);

            if (laborItem == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            laborItem.Vendor = db.Vendors.Find(laborItem.VendorId);
            LaborItemApiType lit  = new LaborItemApiType(laborItem);
            string           json = JsonConvert.SerializeObject(lit);

            return(json);
        }
Пример #3
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            LaborItem item     = (LaborItem)validationContext.ObjectInstance;
            var       property = validationContext.ObjectType.GetProperty("State");

            if (property != null)
            {
                var state = property.GetValue(validationContext.ObjectInstance, null);
                if (state.ToString() == "Unadded" || state.ToString() == "Deleted" || state.ToString() == "Fixed")
                {
                    return(ValidationResult.Success);
                }
            }

            if (((item.pph != null && item.ppp != null) && (item.pph != 0 && item.ppp != 0)) || (item.pph == null && item.ppp == null))
            {
                return(new ValidationResult("Please specify either $/hour or $/piece, but not both"));
            }
            return(ValidationResult.Success);
        }
        string StylesInUse(LaborItem li)
        {
            string       s      = null;
            List <Style> styles = db.StyleLaborItems.Where(sli => sli.LaborTableId == li.Id).Select(sli => sli.Style).ToList();

            foreach (Style sty in styles)
            {
                if (sty == styles.First())
                {
                    s = sty.StyleName; continue;
                }
                if (sty == styles.Last())
                {
                    s += $" and {sty.StyleName}"; continue;
                }
                s += $", {sty.StyleName}";
            }

            return(s);
        }