Ejemplo n.º 1
0
        public static Printed GetPrinted(int id, string dateFlag)
        {
            var printed = Context.Printed.FirstOrDefault(p => p.ProductId == id && p.DateFlag == dateFlag);

            if (printed == null)
            {
                printed = new Printed {
                    ProductId = id, DateFlag = dateFlag, TotalNum = 0
                };
                Context.Printed.Add(printed);
                Context.SaveChanges();
            }
            return(printed);
        }
Ejemplo n.º 2
0
        public static bool SetPrinted(Printed printed, int max, int add)
        {
            if (printed.TotalNum + add > max)
            {
                return(false);
            }

retry:
            try
            {
                printed.TotalNum += add;
                Context.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                Thread.Sleep(200);
                goto retry;
            }
        }