public ActionResult _EditCategory(string fullName, string note, bool status = false, int id = 0)
        {
            // kiểm tra quyền thêm sửa
            var sys = CheckActiveMenu.ReturnActive(SystemMessageConst.TypeAction.Update);

            if (sys.IsSuccess == false)
            {
                return(Json(new { result = sys }, JsonRequestBehavior.AllowGet));
            }

            var db = new ManagerCategoryBusiness();

            tbl_LoaiSP serviceCustomer = new tbl_LoaiSP();

            serviceCustomer.category_name = fullName;
            serviceCustomer.description   = note;
            serviceCustomer.isactive      = status;
            serviceCustomer.id            = id;

            var result = db.EditCategory(serviceCustomer);

            CheckRuleAndSaveLog.ReturnCheckRuleAndSaveLog(DbLogType.Update.ToString(), result.IsSuccess, JsonConvert.SerializeObject(new { log = "CapNhatThongTinDVT", newtdata = serviceCustomer }, Newtonsoft.Json.Formatting.Indented, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            }));


            return(Json(new { result }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public SystemMessage AddCategory(tbl_LoaiSP customer)
        {
            SystemMessage systemMessage = new SystemMessage();

            try
            {
                var check = ValidateCustomer(customer);
                if (check != null)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = check;
                    return(systemMessage);
                }

                var checkSDT = db.tbl_LoaiSP.FirstOrDefault(m => m.category_name == customer.category_name);
                if (checkSDT != null)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = "Tên loại sản phẩm đã tồn tại";
                    return(systemMessage);
                }

                db.tbl_LoaiSP.Add(customer);
                db.SaveChanges();
                systemMessage.IsSuccess = true;
                systemMessage.Message   = SystemMessageConst.systemmessage.AddSuccess;
                return(systemMessage);
            }
            catch (Exception e)
            {
                systemMessage.IsSuccess = false;
                systemMessage.Message   = e.ToString();
                return(systemMessage);
            }
        }
Exemplo n.º 3
0
        public string ValidateCustomer(tbl_LoaiSP customer)
        {
            string rs  = null;
            var    vld = new ValidateUtils();

            rs = vld.CheckRequiredField(customer.category_name, "Tên loại sản phẩm", 1, 50);
            if (rs != null)
            {
                return(rs);
            }
            return(null);
        }
Exemplo n.º 4
0
        public SystemMessage EditCategory(tbl_LoaiSP customer)
        {
            SystemMessage systemMessage = new SystemMessage();

            try
            {
                var check = ValidateCustomer(customer);
                if (check != null)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = check;
                    return(systemMessage);
                }

                var checkExisted = db.tbl_LoaiSP.FirstOrDefault(ob => ob.id == customer.id);
                if (checkExisted == null)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = SystemMessageConst.systemmessage.NoData;
                    return(systemMessage);
                }

                var checkten = db.tbl_LoaiSP.FirstOrDefault(m => m.category_name == customer.category_name && m.id != customer.id);
                if (checkten != null)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = "Tên loại sản phẩm đã tồn tại";
                    return(systemMessage);
                }

                checkExisted.category_name = customer.category_name;
                checkExisted.description   = customer.description;
                checkExisted.isactive      = customer.isactive;

                db.SaveChanges();
                systemMessage.IsSuccess = true;
                systemMessage.Message   = SystemMessageConst.systemmessage.EditSuccess;
                return(systemMessage);
            }
            catch (Exception e)
            {
                systemMessage.IsSuccess = false;
                systemMessage.Message   = e.ToString();
                return(systemMessage);
            }
        }
Exemplo n.º 5
0
        public ReturnListCategory BS_ListCategory(string searchValue, int currPage, int recodperpage)
        {
            ReturnListCategory result = new ReturnListCategory();

            List <tbl_LoaiSP> list = new List <tbl_LoaiSP>();
            SqlConnection     con  = new SqlConnection();

            con = Connection.Connect.GetConnect();
            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "Getall_category";
            cmd.Parameters.Add(new SqlParameter("@searchValue", searchValue));
            cmd.Parameters.Add(new SqlParameter("@currPage", currPage));
            cmd.Parameters.Add(new SqlParameter("@recodperpage", 10));
            cmd.Parameters.Add("@totalCount", SqlDbType.Int).Direction = ParameterDirection.Output;
            cmd.Connection = con;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable      dt = new DataTable();

            da.Fill(dt);
            int total = Convert.ToInt32(cmd.Parameters["@totalCount"].Value);

            foreach (DataRow rowItem in dt.Rows)
            {
                tbl_LoaiSP customer = new tbl_LoaiSP();

                customer.id            = Int32.Parse(rowItem["id"].ToString());
                customer.category_name = rowItem["category_name"].ToString();
                customer.isactive      = bool.Parse(rowItem["isactive"].ToString());
                customer.description   = rowItem["description"].ToString();
                list.Add(customer);
            }

            result.Data  = list;
            result.Total = total;
            return(result);
        }