Esempio n. 1
0
        public static string GetUsername(int id)
        {
            IDbConnection connectDB = new SqlConnection(Common.ConnectString);

            try
            {
                string query    = "select Username from AppUsers where Id = " + id;
                string username = connectDB.Query <string>(query).FirstOrDefault();
                return(SString.ConverToString(username));
            }
            catch (Exception ex)
            {
                LogService.WriteException(ex);
                return("");
            }
        }
Esempio n. 2
0
        public string GetValueLink2ObjectID(int tableNameID, int actionID, int objectID, string objectValue)
        {
            try
            {
                string value = "";
                if (actionID == (int)Common.ActionID.Delete)
                {
                    return(objectValue);
                }

                if (tableNameID == (int)Common.TableName.Account)
                {
                    var temp = appUserService.GetByPrimaryKey(objectID);
                    if (temp != null)
                    {
                        value = temp.Username;
                        return(value);
                    }
                }
                else if (tableNameID == (int)Common.TableName.Collection)
                {
                    var temp = collectionService.GetByPrimaryKey(objectID);
                    if (temp != null)
                    {
                        value = temp.CollectionName;
                        return(value);
                    }
                }
                else if (tableNameID == (int)Common.TableName.Customer)
                {
                    var temp = customerService.GetByPrimaryKey(objectID);
                    if (temp != null)
                    {
                        value = temp.CustomerFirstName + " " + temp.CustomerLastName;
                        return(value);
                    }
                }
                else if (tableNameID == (int)Common.TableName.Product)
                {
                    var temp = productService.GetByPrimaryKey(objectID);
                    if (temp != null)
                    {
                        value = temp.ProductName;
                        return(value);
                    }
                }
                else if (tableNameID == (int)Common.TableName.TblOrder)
                {
                    var temp = tblOrderService.GetByPrimaryKey(objectID);
                    if (temp != null)
                    {
                        value = "#" + SString.ConverToString(Common.BaseNumberOrder + temp.Number);
                        return(value);
                    }
                }
            }
            catch (Exception ex)
            {
                LogService.WriteException(ex);
                return(objectValue);
            }
            return(objectValue);
        }
Esempio n. 3
0
        public string detail(Collection collection, HttpPostedFileBase file)
        {
            try
            {
                collection.TemplateLayouts = new SelectList(new List <SelectListItem>
                {
                    new SelectListItem {
                        Selected = true, Text = "collection", Value = "collection"
                    },
                    new SelectListItem {
                        Selected = true, Text = "collection.list", Value = "collection.list"
                    },
                }, "Value", "Text", "1");

                //create collectionID for all rules
                foreach (var item in collection.TblRules)
                {
                    item.CollectionID = collection.CollectionID;
                }

                string strErrorMessage = "";
                bool   flg             = false;
                if (ModelState.IsValid)
                {
                    // insert collection
                    if (collection.CollectionType == "custom")
                    {
                        collection.ConditionForCollection = false;
                    }
                    else if (collection.CollectionType == "smart")
                    {
                        for (int i = 0; i < collection.TblRules.Count; i++)
                        {
                            if (string.IsNullOrEmpty(collection.TblRules[i].ConditionValue))
                            {
                                strErrorMessage += "Giá trị lọc không được để trống<br/>";
                                flg              = true;
                            }
                        }
                    }
                    if (!flg)
                    {
                        collection.ModifiedDateTime = SDateTime.GetYYYYMMddHmmSSNow();
                        bool result = collectionService.Update(collection);

                        if (result)
                        {
                            LogService.WriteLog2DB(accountService.GetUserId(User.Identity.GetUserName()), (int)Common.ActionID.Update, collection.CollectionID, SDateTime.GetYYYYMMddHmmSSNow(), General.GetIPAddress(), TableNameID, collection.CollectionName);

                            // delete image collection
                            string folder = Server.MapPath("~/assets/uploads/collections/") + collection.CollectionID;
                            ImageService.DeleteSubFolder(folder);

                            // update collection image url
                            string imageUrl = UploadImage(collection.CollectionID, file);
                            if (!string.IsNullOrEmpty(imageUrl))
                            {
                                collection.CollectionImage = imageUrl;
                                collectionService.Update(collection);
                            }
                            if (collection.CollectionType == "smart")
                            {
                                List <TblRule> listRuleExisted = tblRuleService.SelectByCollectionID(collection.CollectionID);
                                if (listRuleExisted == null || listRuleExisted.Count <= 0)
                                {
                                    for (int i = 0; i < collection.TblRules.Count; i++)
                                    {
                                        if (tblRuleService.CheckRuleValid(collection.TblRules[i]))
                                        {
                                            tblRuleService.Insert(collection.TblRules[i]);
                                        }
                                    }
                                }
                                else
                                {
                                    for (int i = 0; i < collection.TblRules.Count; i++)
                                    {
                                        bool flgInsert = true;
                                        for (int j = 0; j < listRuleExisted.Count; j++)
                                        {
                                            if (tblRuleService.Equals(listRuleExisted[j], collection.TblRules[i]))
                                            {
                                                flgInsert = false;
                                            }
                                        }
                                        if (flgInsert)
                                        {
                                            tblRuleService.Insert(collection.TblRules[i]);
                                        }
                                    }
                                    for (int i = 0; i < listRuleExisted.Count; i++)
                                    {
                                        bool flgDelete = true;
                                        for (int j = 0; j < collection.TblRules.Count; j++)
                                        {
                                            if (tblRuleService.Equals(listRuleExisted[i], collection.TblRules[j]))
                                            {
                                                flgDelete = false;
                                            }
                                        }
                                        if (flgDelete)
                                        {
                                            tblRuleService.DeleteByPrimary(listRuleExisted[i].RuleID);
                                        }
                                    }
                                }
                                // get list prodct by all condition in collection
                                string linkCondition = "";
                                if (collection.ConditionForCollection)
                                {
                                    linkCondition = "and";
                                }
                                else
                                {
                                    linkCondition = "or";
                                }
                                string                   strConditionProductByRule      = "1=1 and " + tblRuleService.GetConditionProductByListRule(collection.TblRules, linkCondition);
                                List <Product>           listProductByRulesOfCollection = productService.GetByWhere(strConditionProductByRule);
                                List <CollectionProduct> listCollectionProductExisted   = collectionProductService.GetByCollectionID(collection.CollectionID);
                                if (listProductByRulesOfCollection != null && listProductByRulesOfCollection.Count > 0)
                                {
                                    List <int> listProductAdd    = new List <int>();
                                    List <int> listProductDelete = new List <int>();
                                    if (listCollectionProductExisted == null || listCollectionProductExisted.Count <= 0)
                                    {
                                        for (int i = 0; i < listProductByRulesOfCollection.Count; i++)
                                        {
                                            collectionProductService.Insert(new CollectionProduct
                                            {
                                                CollectionID = collection.CollectionID,
                                                ProductID    = listProductByRulesOfCollection[i].ProductID,
                                            });
                                        }
                                    }
                                    else
                                    {
                                        for (int i = 0; i < listProductByRulesOfCollection.Count; i++)
                                        {
                                            bool flgInsert = true;
                                            for (int j = 0; j < listCollectionProductExisted.Count; j++)
                                            {
                                                if (listCollectionProductExisted[j].ProductID == listProductByRulesOfCollection[i].ProductID)
                                                {
                                                    flgInsert = false;
                                                }
                                            }
                                            if (flgInsert)
                                            {
                                                collectionProductService.Insert(new CollectionProduct
                                                {
                                                    CollectionID = collection.CollectionID,
                                                    ProductID    = listProductByRulesOfCollection[i].ProductID,
                                                });
                                            }
                                        }
                                        for (int i = 0; i < listCollectionProductExisted.Count; i++)
                                        {
                                            bool flgDelete = true;
                                            for (int j = 0; j < listProductByRulesOfCollection.Count; j++)
                                            {
                                                if (listProductByRulesOfCollection[j].ProductID == listCollectionProductExisted[i].ProductID)
                                                {
                                                    flgDelete = false;
                                                }
                                            }
                                            if (flgDelete)
                                            {
                                                collectionProductService.DeleteByPrimary(listCollectionProductExisted[i].ID);
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    collectionProductService.DeleteByCollectionID(collection.CollectionID);
                                }
                            }
                            return(SString.ConverToString(collection.CollectionID));
                        }
                    }
                }
                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        strErrorMessage += error.ErrorMessage;
                    }
                }
                return(strErrorMessage);
            }
            catch (Exception ex)
            {
                LogService.WriteException(ex);
                return(ex.Message);
            }
        }