예제 #1
0
        public ReturnType UpdateStockCat(string stockcatCode, string catName)
        {
            try
            {
                using (AladingEntities alading = new AladingEntities(AppSettings.GetConnectionString()))
                {
                    StockCat result = alading.StockCat.Where(p => p.StockCid == stockcatCode).FirstOrDefault();
                    if (result == null)
                    {
                        return(ReturnType.NotExisted);
                    }

                    result.StockCatName = catName;

                    alading.SaveChanges();
                    return(ReturnType.Success);
                }
            }
            catch (SqlException sex)
            {
                return(ReturnType.ConnFailed);
            }
            catch (Exception ex)
            {
                return(ReturnType.OthersError);
            }
        }
예제 #2
0
        public ReturnType UpdateStockCat(StockCat stockcat)
        {
            try
            {
                using (AladingEntities alading = new AladingEntities(AppSettings.GetConnectionString()))
                {
                    /*StockCat result = alading.StockCat.Where(p => p.StockCatID == stockcat.StockCatID).FirstOrDefault();*/
                    StockCat result = alading.StockCat.Where(p => p.StockCid == stockcat.StockCid).FirstOrDefault();
                    if (result == null)
                    {
                        return(ReturnType.NotExisted);
                    }

                    //result.StockCid = stockcat.StockCid;

                    result.ParentCid = stockcat.ParentCid;

                    result.StockCatName = stockcat.StockCatName;

                    result.IsParent = stockcat.IsParent;

                    alading.SaveChanges();
                    return(ReturnType.Success);
                }
            }
            catch (SqlException sex)
            {
                return(ReturnType.ConnFailed);
            }
            catch (Exception ex)
            {
                return(ReturnType.OthersError);
            }
        }
예제 #3
0
 public ReturnType DeleteStockCat(string cid)
 {
     try
     {
         using (AladingEntities alading = new AladingEntities(AppSettings.GetConnectionString()))
         {
             StockCat stockCat = alading.StockCat.FirstOrDefault(c => c.StockCid == cid);
             if (stockCat != null)
             {
                 if (stockCat.IsParent)
                 {
                     return(ReturnType.Conflicted);
                 }
                 IEnumerable <StockProp>      propList  = alading.StockProp.Where(c => c.StockCid == cid);
                 IEnumerable <StockPropValue> valueList = alading.StockPropValue.Where(c => c.StockCid == cid);
                 foreach (StockProp stockProp in propList)
                 {
                     alading.DeleteObject(stockProp);
                 }
                 foreach (StockPropValue value in valueList)
                 {
                     alading.DeleteObject(value);
                 }
                 List <StockCat> catList = alading.StockCat.Where(c => c.ParentCid == stockCat.ParentCid).ToList();
                 if (catList.Count == 1)
                 {
                     StockCat fatherStockCat = alading.StockCat.FirstOrDefault(c => c.StockCid == stockCat.ParentCid);
                     fatherStockCat.IsParent = false;
                     alading.SaveChanges();
                 }
                 alading.DeleteObject(stockCat);
                 alading.SaveChanges();
                 return(ReturnType.Success);
             }
             else
             {
                 return(ReturnType.NotExisted);
             }
         }
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
예제 #4
0
            public async Task <StockCatDto> Handle(Command request, CancellationToken cancellationToken)
            {
                var stockCat = new StockCat
                {
                    Title = request.Title
                };

                _context.StockCats.Add(stockCat);
                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    var toReturn = _mapper.Map <StockCat, StockCatDto>(stockCat);
                    return(toReturn);
                }

                throw new Exception("Problem saving changes");
            }
예제 #5
0
 public ReturnType RemoveStockCat(string stockCid)
 {
     try
     {
         using (AladingEntities alading = new AladingEntities(AppSettings.GetConnectionString()))
         {
             StockCat result = alading.StockCat.FirstOrDefault(p => p.StockCid == stockCid);
             if (result == null)
             {
                 return(ReturnType.NotExisted);
             }
             else
             {
                 if (result.ParentCid != "0")
                 {
                     //查找此类目的父类目是否有其他子类目,没有则父类目IsParent为false
                     List <StockCat> catList = alading.StockCat.Where(i => i.ParentCid == result.ParentCid).ToList();
                     //只有一个子类目即本stockCid
                     if (catList.Count == 1)
                     {
                         StockCat parentCat = alading.StockCat.FirstOrDefault(i => i.StockCid == result.ParentCid);
                         if (parentCat != null)
                         {
                             parentCat.IsParent = false;
                         }
                     }
                 }
             }
             alading.DeleteObject(result);
             alading.SaveChanges();
             return(ReturnType.Success);
         }
     }
     catch (SqlException sex)
     {
         return(ReturnType.ConnFailed);
     }
     catch (System.Exception ex)
     {
         return(ReturnType.OthersError);
     }
 }
예제 #6
0
        public ReturnType UpdateStockCat(string stockcatCode, StockCat stockcat)
        {
            try
            {
                using (AladingEntities alading = new AladingEntities(AppSettings.GetConnectionString()))
                {
                    /*var result = alading.StockCat.Where(p => p.StockCatID == stockcatID).ToList();*/
                    var result = alading.StockCat.Where(p => p.StockCid == stockcatCode).ToList();
                    if (result.Count == 0)
                    {
                        return(ReturnType.NotExisted);
                    }

                    StockCat ob = result.First();
                    ob.StockCid     = stockcat.StockCid;
                    ob.ParentCid    = stockcat.ParentCid;
                    ob.StockCatName = stockcat.StockCatName;
                    ob.IsParent     = stockcat.IsParent;

                    if (alading.SaveChanges() == 1)
                    {
                        return(ReturnType.Success);
                    }
                    else
                    {
                        return(ReturnType.OthersError);
                    }
                }
            }
            catch (SqlException sex)
            {
                return(ReturnType.ConnFailed);
            }
            catch (System.Exception ex)
            {
                return(ReturnType.OthersError);
            }
        }
예제 #7
0
 public ReturnType AddStockCat(StockCat stockcat)
 {
     try
     {
         using (AladingEntities alading = new AladingEntities(AppSettings.GetConnectionString()))
         {
             alading.AddToStockCat(stockcat);
             if (stockcat.ParentCid != "0")
             {
                 StockCat result = alading.StockCat.FirstOrDefault(i => i.StockCid == stockcat.ParentCid);
                 if (result != null)
                 {
                     result.IsParent = true;
                 }
             }
             alading.SaveChanges();
             return(ReturnType.Success);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #8
0
 public static ReturnType UpdateStockCat(string stockcatCode, StockCat stockcat)
 {
     return(DataProviderClass.Instance().UpdateStockCat(stockcatCode, stockcat));
 }
예제 #9
0
 public static ReturnType AddStockCat(StockCat stockcat)
 {
     return(DataProviderClass.Instance().AddStockCat(stockcat));
 }