コード例 #1
0
 /// <summary>
 /// Insert Category
 /// </summary>
 /// <param name="data">Information Cateogy</param>
 /// <returns>Number Affected Row</returns>
 public static Tuple <ErrorObject, string> Category(tblCategory data)
 {
     erros = new ErrorObject();
     try
     {
         using (EileenGaldamezEntities db = new EileenGaldamezEntities())
         {
             int propertyFind = db.tblCategory.Count();
             if (propertyFind > 0)
             {
                 data.id = db.tblCategory.Max(s => s.id + 1);
             }
             else
             {
                 data.id = 1;
             }
             db.tblCategory.Add(data);
             result  = db.SaveChanges();
             Message = "Affected Row: " + result.ToString();
             return(new Tuple <ErrorObject, string>(erros.IfError(false), Message));
         }
     }
     catch (Exception ex)
     {
         erros.InfoError(ex);
         return(new Tuple <ErrorObject, string>(erros, String.Empty));
     }
 }
コード例 #2
0
            /// <summary>
            /// Update Category
            /// </summary>
            /// <param name="data">Category Information</param>
            /// <returns>Number Affected Row</returns>
            public static Tuple <ErrorObject, string> Category(tblCategory data)
            {
                erros = new ErrorObject();
                try
                {
                    using (EileenGaldamezEntities db = new EileenGaldamezEntities())
                    {
                        var row = db.tblCategory.Single(p => p.id == data.id);
                        row.name         = data.name;
                        row.idCategory   = data.idCategory;
                        row.idCellarArea = data.idCellarArea;
                        row.detail       = data.detail;
                        row.upDateDate   = data.upDateDate;
                        result           = db.SaveChanges();
                        Message          = "Affected Row: " + result.ToString();

                        return(new Tuple <ErrorObject, string>(erros.IfError(false), Message));
                    }
                }
                catch (Exception ex)
                {
                    erros.InfoError(ex);
                    return(new Tuple <ErrorObject, string>(erros, String.Empty));
                }
            }
コード例 #3
0
            /// <summary>
            /// Return Department Information
            /// </summary>
            /// <param name="CategoryID">Category ID</param>
            /// <returns>Department Information</returns>
            public static Tuple <ErrorObject, tblCategory> GetCategory(int CategoryID)
            {
                tblCategory c = new tblCategory();

                erros = new ErrorObject();
                try
                {
                    using (EileenGaldamezEntities db = new EileenGaldamezEntities())
                    {
                        c = db.tblCategory.Find(CategoryID);
                        return(new Tuple <ErrorObject, tblCategory>(erros.IfError(false), c));
                    }
                }
                catch (Exception ex)
                {
                    erros.InfoError(ex);
                    return(new Tuple <ErrorObject, tblCategory>(erros, c));
                }
            }
コード例 #4
0
ファイル: CategoryData.cs プロジェクト: gvhung/HSCM
            /// <summary>
            /// Update Category
            /// </summary>
            /// <param name="data">Category Information</param>
            /// <returns>Number Affected Row</returns>
            public static Tuple <ErrorObject, string> Category(tblCategory data)
            {
                erros = new ErrorObject();
                try
                {
                    using (HSCMEntities db = new HSCMEntities())
                    {
                        db.Entry(data).State = EntityState.Modified;
                        result  = db.SaveChanges();
                        Message = "Affected Row: " + result.ToString();

                        return(new Tuple <ErrorObject, string>(erros.IfError(false), Message));
                    }
                }
                catch (Exception ex)
                {
                    erros.InfoError(ex);
                    return(new Tuple <ErrorObject, string>(erros, String.Empty));
                }
            }
コード例 #5
0
            /// <summary>
            /// Update Category and All category child
            /// </summary>
            /// <param name="data">Category information</param>
            /// <returns>Number Affected Row</returns>
            public static Tuple <ErrorObject, string> CategoryAndAllChildCellarArea(tblCategory data)
            {
                List <int> Child = new List <int>();

                erros = new ErrorObject();
                try
                {
                    using (EileenGaldamezEntities db = new EileenGaldamezEntities())
                    {
                        var row = db.tblCategory.Single(p => p.id == data.id);
                        row.name         = data.name;
                        row.idCategory   = data.idCategory;
                        row.idCellarArea = data.idCellarArea;
                        row.detail       = data.detail;
                        row.upDateDate   = data.upDateDate;
                        result           = db.SaveChanges();
                        Message          = "Affected Row: " + result.ToString();

                        Child = (
                            from C in db.tblCategory
                            where C.idCategory == data.id
                            select C.id).ToList();

                        if (Child.Count > 0)
                        {
                            foreach (var item in Child)
                            {
                                var row2 = db.tblCategory.Single(p => p.id == item);
                                row2.idCellarArea = data.idCellarArea;
                                db.SaveChanges();
                            }
                        }
                        return(new Tuple <ErrorObject, string>(erros.IfError(false), Message));
                    }
                }
                catch (Exception ex)
                {
                    erros.InfoError(ex);
                    return(new Tuple <ErrorObject, string>(erros, String.Empty));
                }
            }