Example #1
0
        public int AddOrUpdate(int curruserid)
        {
            IDbConnection dbConn = new OrmliteConnection().openConn();

            try
            {
                //var isexist = dbConn.GetByIdOrDefault<AuthUser>(10);
                var isexist = dbConn.FirstOrDefault <AuthUser>("entryid={0}", this.entryid);
                if (isexist == null)
                {
                    this.isactive  = true;
                    this.createdat = DateTime.Now;
                    this.createdby = curruserid;
                    this.updatedat = DateTime.Now;
                    this.updatedby = curruserid;
                    this.lastlogin = DateTime.Now;
                    dbConn.Insert <AuthUser>(this);
                    long lastInsertId = dbConn.GetLastInsertId();
                    dbConn.Close();
                    this.entryid = Convert.ToInt32(lastInsertId);
                    return(this.entryid);
                }
                else if (isexist != null)
                {
                    this.isactive      = isexist.isactive;
                    this.loginprovider = isexist.loginprovider;
                    this.logintype     = isexist.logintype;
                    this.createdat     = isexist.createdat;
                    this.createdby     = isexist.createdby;
                    this.updatedat     = DateTime.Now;
                    this.updatedby     = curruserid;
                    this.lastlogin     = DateTime.Now;
                    dbConn.Update <AuthUser>(this);
                    dbConn.Close();
                    return(this.entryid);
                }
                else
                {
                    return(0);
                }
            }
            catch (Exception ex)
            {
                return(0);
            }
        }
        public ActionResult Create(Master_Announcement item)
        {
            //if (form.AllKeys.Contains("TextContent"))
            //{
            //    item.TextContent = form.Get("TextContent");
            //}

            //CHECK IS NULL VALUE
            if (string.IsNullOrEmpty(item.TextContent))
            {
                item.TextContent = "";
            }
            if (string.IsNullOrEmpty(item.HTMLContent))
            {
                item.HTMLContent = "";
            }
            if (string.IsNullOrEmpty(item.Title))
            {
                item.Title = "";
            }

            IDbConnection dbConn = new OrmliteConnection().openConn();

            try
            {
                var isExist = dbConn.GetByIdOrDefault <Master_Announcement>(item.AnnouncementID);

                if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
                {
                    if (isExist != null)
                    {
                        return(Json(new { success = false, message = "Đối tượng này đã tồn tại." }));
                    }
                    item.CreatedAt = DateTime.Now;
                    item.CreatedBy = currentUser.UserID;

                    dbConn.Insert <Master_Announcement>(item);
                    long lastInsertId = dbConn.GetLastInsertId();
                    dbConn.Close();
                    return(Json(new { success = true, AnnouncementID = lastInsertId, createdat = item.CreatedAt, createdby = item.CreatedBy }));
                }
                else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
                {
                    item.UpdatedAt = DateTime.Now;
                    item.CreatedBy = currentUser.UserID;
                    dbConn.Update <Master_Announcement>(item);
                    dbConn.Close();
                    return(Json(new { success = true }));
                }
                else
                {
                    return(Json(new { success = false, message = "You don't have permission" }));
                }
            }
            catch (Exception ex)
            {
                log.Error("AD_Announcement - Create - " + ex.Message);
                return(Json(new { success = false, message = ex.Message }));
            }
            finally
            {
                dbConn.Close();
            }
        }
Example #3
0
        public ActionResult Create(FormCollection form)
        {
            IDbConnection db = new OrmliteConnection().openConn();

            try
            {
                if (!string.IsNullOrEmpty(form["RoleName"]))
                {
                    var item = new Auth_Role();
                    item.RoleName = form["RoleName"];
                    item.IsActive = form["IsActive"] != null?Convert.ToBoolean(form["IsActive"]) : false;

                    item.Note = !string.IsNullOrEmpty(form["Note"]) ? form["Note"] : "";
                    if (userAsset.ContainsKey("Insert") && userAsset["Insert"] &&
                        string.IsNullOrEmpty(form["RoleID"]))    // Tạo mới
                    {
                        item.RowCreatedAt = DateTime.Now;
                        item.RowCreatedBy = currentUser.UserID;
                        db.Insert <Auth_Role>(item);
                        long lastID = db.GetLastInsertId();
                        if (lastID > 0)
                        {
                            // Thêm Role vào Auth_Action
                            db.ExecuteSql("EXEC p_Auth_Role_GenerateAction_By_RoleID " + lastID + "," + currentUser.UserID);
                        }
                        return(Json(new { success = true, insert = true, RoleID = lastID, createdat = item.RowCreatedAt, createdby = item.RowCreatedBy }));
                    }
                    else if (userAsset.ContainsKey("Insert") && userAsset["Insert"] &&
                             Convert.ToInt32(form["RoleID"]) > 0 &&
                             Convert.ToInt32(form["IsCopy"]) == 1) // Sao chép
                    {
                        item.RoleID       = Convert.ToInt32(form["RoleID"]);
                        item.RowCreatedAt = DateTime.Now;
                        item.RowCreatedBy = currentUser.UserID;
                        db.Insert <Auth_Role>(item);
                        long lastID = db.GetLastInsertId();
                        if (lastID > 0)
                        {
                            // Sao chép Action RoleID đã chọn vào RoleID vừa tạo
                            db.ExecuteSql("p_Auth_Role_CopyAction_By_RoleID " + item.RoleID + "," + lastID + "," + currentUser.UserID);
                        }
                        return(Json(new { success = true, insert = true, RoleID = lastID, createdat = item.RowCreatedAt, createdby = item.RowCreatedBy }));
                    }
                    else if (userAsset.ContainsKey("Update") && userAsset["Update"] &&
                             Convert.ToInt32(form["RoleID"]) > 0)   // Cập nhật
                    {
                        item.RoleID       = Convert.ToInt32(form["RoleID"]);
                        item.RowCreatedAt = DateTime.Parse(form["RowCreatedAt"]);
                        item.RowCreatedBy = form["RowCreatedBy"];
                        item.RowUpdatedAt = DateTime.Now;
                        item.RowUpdatedBy = currentUser.UserID;
                        if (item.RowCreatedBy != "system")
                        {
                            db.Update <Auth_Role>(item);
                        }

                        return(Json(new { success = true, RoleID = item.RoleID }));
                    }
                    else
                    {
                        return(Json(new { success = false, message = "Bạn không có quyền" }));
                    }
                }
                else
                {
                    return(Json(new { success = false, message = "Chưa nhập giá trị" }));
                }
            }
            catch (Exception e)
            {
                log.Error("HOAdminAuthRole - Create - " + e.Message);
                return(Json(new { success = false, message = e.Message }));
            }
            finally { db.Close(); }
        }
Example #4
0
        public string CreateProduct(Merchant_Product product, Merchant_Product_Hierarchy hierarchy, List <Merchant_Product_Image> listimage, List <Merchant_Product_Property> listproperty, string connectstring)
        {
            using (var db = new OrmliteConnection().openConn(connectstring))
            {
                //using (var dbTrans = db.OpenTransaction(IsolationLevel.ReadCommitted))
                {
                    try
                    {
                        if (!string.IsNullOrEmpty(product.ma_san_pham))
                        {
                            var Checkproduct = db.FirstOrDefault <Merchant_Product>(s => s.ma_san_pham == product.ma_san_pham);
                            if (Checkproduct != null)
                            {
                                return(UpdateProduct(product, hierarchy, listimage, listproperty, connectstring));
                            }
                        }
                        if (product.id == 0 && !String.IsNullOrEmpty(product.nguoi_tao) && !String.IsNullOrEmpty(product.ma_gian_hang))
                        {
                            var lastId = db.FirstOrDefault <Merchant_Product>("SELECT TOP 1 * FROM Merchant_Product ORDER BY ma_san_pham DESC");
                            if (lastId != null && lastId.ma_san_pham.Contains("SP"))
                            {
                                var nextNo = Int32.Parse(lastId.ma_san_pham.Substring(2, 7)) + 1;
                                product.ma_san_pham = "SP" + String.Format("{0:0000000}", nextNo);
                            }
                            else
                            {
                                product.ma_san_pham = "SP" + "0000001";
                            }
                            product.ma_loai_san_pham = !string.IsNullOrEmpty(product.ma_loai_san_pham) ? product.ma_loai_san_pham : "";
                            product.part_no          = !string.IsNullOrEmpty(product.part_no) ? product.part_no : "";
                            product.mo_ta            = !string.IsNullOrEmpty(product.mo_ta) ? product.mo_ta : "";
                            product.noi_dung         = !string.IsNullOrEmpty(product.noi_dung) ? product.noi_dung : "";
                            product.tu_khoa          = !string.IsNullOrEmpty(product.tu_khoa) ? product.tu_khoa : "";
                            product.tag                 = !string.IsNullOrEmpty(product.tag) ? product.tag : "";
                            product.slug                = !string.IsNullOrEmpty(product.slug) ? product.slug : "";
                            product.xuat_xu             = !string.IsNullOrEmpty(product.xuat_xu) ? product.xuat_xu : "";
                            product.model               = !string.IsNullOrEmpty(product.model) ? product.model : "";
                            product.trang_thai          = AllConstant.trang_thai.DANG_SU_DUNG;           //giá trị đang hoạt động
                            product.trang_thai_duyet    = AllConstant.trang_thai_duyet.CHUA_DUYET;       //giá trị chờ duyệt
                            product.trang_thai_xuat_ban = AllConstant.trang_thai_xuat_ban.CHUA_XUAT_BAN; //giá trị chờ xuất bản
                            product.nguoi_xuat_ban      = product.nguoi_duyet = "";
                            product.ngay_xuat_ban       = product.ngay_duyet = product.ngay_cap_nhat = DateTime.Parse("1900-01-01");
                            product.ngay_tao            = DateTime.Now;
                            db.Insert(product);
                            Int64 productId = (Int64)db.GetLastInsertId();

                            //List<SqlParameter> param = new List<SqlParameter>();
                            //param.Add(new SqlParameter("@id", productId));
                            //new SqlHelper().ExecuteNoneQuery("p_UpdateSlugForMerchantProduct", param);


                            if (hierarchy.id == 0)
                            {
                                hierarchy.ma_san_pham   = product.ma_san_pham;
                                hierarchy.ma_gian_hang  = product.ma_gian_hang;
                                hierarchy.ngay_tao      = DateTime.Now;
                                hierarchy.nguoi_tao     = product.nguoi_tao;
                                hierarchy.ngay_cap_nhat = DateTime.Parse("1900-01-01");
                                hierarchy.trang_thai    = AllConstant.trang_thai.DANG_SU_DUNG; // Giá trị đang hoạt động
                                db.Insert(hierarchy);
                                if (listimage != null)
                                {
                                    foreach (Merchant_Product_Image item in listimage)
                                    {
                                        if (item.id == 0)
                                        {
                                            item.ma_san_pham  = product.ma_san_pham;
                                            item.ma_gian_hang = product.ma_gian_hang;
                                            item.ngay_tao     = DateTime.Now;
                                            item.nguoi_tao    = product.nguoi_tao;
                                            db.Insert(item);
                                        }
                                        else
                                        {
                                            //dbTrans.Rollback();
                                            return("Lỗi khi tạo thumbnail hình ảnh");
                                        }
                                    }
                                }
                                if (listproperty != null)
                                {
                                    foreach (Merchant_Product_Property item in listproperty)
                                    {
                                        if (item.id == 0)
                                        {
                                            item.ma_gian_hang  = product.ma_gian_hang;
                                            item.ma_san_pham   = product.ma_san_pham;
                                            item.ngay_tao      = DateTime.Now;
                                            item.nguoi_tao     = product.nguoi_tao;
                                            item.ngay_cap_nhat = DateTime.Parse("1900-01-01");
                                            db.Insert(item);
                                        }
                                        else
                                        {
                                            //dbTrans.Rollback();
                                            return("Lỗi khi tạo thuộc tính");
                                        }
                                    }
                                }
                                //dbTrans.Commit();
                                new Merchant_Product_Warehouse_DAO().CreateUpdate(product.ma_san_pham, product.ma_gian_hang, product.nguoi_tao, connectstring);
                                return("true@@" + product.ma_san_pham);
                            }
                            else
                            {
                                // dbTrans.Rollback();
                                return("Lỗi khi tạo ngành hàng");
                            }
                        }
                        else
                        {
                            // dbTrans.Rollback();
                            return("Lỗi khi tạo sản phẩm");
                        }
                    }
                    catch (Exception ex)
                    {
                        //dbTrans.Rollback();
                        return("Lỗi thao tác dữ liệu");
                    }
                }
            }
        }