public ActionResult EditCategory(tblCategory categoryModel, HttpPostedFileBase fileUpload)
        {
            if (ModelState.IsValid)
            {
                string pictureLink = "";
                if (fileUpload != null)
                {
                    Image img    = Image.FromStream(fileUpload.InputStream);
                    int   width  = Convert.ToInt32(ConfigurationManager.AppSettings["CategoryWidth"].ToString());
                    int   height = Convert.ToInt32(ConfigurationManager.AppSettings["CategoryHeight"].ToString());

                    pictureLink = "/img/CategoryImage/" + Guid.NewGuid() + Path.GetExtension(fileUpload.FileName);

                    Bitmap bm = new Bitmap(img, width, height);
                    bm.Save(Server.MapPath(pictureLink));
                }
                if (pictureLink == "")
                {
                    categoryModel.PictureLink = "/img/CategoryImage/emptyCategory.jpg";
                }
                else
                {
                    categoryModel.PictureLink = pictureLink;
                }
                db.Entry(categoryModel).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Category"));
            }
            return(View(categoryModel));
        }
        public ActionResult EditCategory(Guid?categoryID)
        {
            List <SelectListItem> listLevelCategory = new List <SelectListItem>();

            listLevelCategory.Add(new SelectListItem {
                Text = "Mức 1", Value = "1"
            });
            listLevelCategory.Add(new SelectListItem {
                Text = "Mức 2", Value = "2"
            });
            //listLevelCategory.Add(new SelectListItem { Text = "Mức 3", Value = "3" });
            ViewData["ListLevelCategory"] = listLevelCategory;
            if (categoryID.HasValue && !categoryID.Value.Equals(Guid.Empty))
            {
                tblCategory tblCategory = new tblCategory();

                tblCategory = Service.GetCategoryByID((Guid)categoryID);
                return(View("Admin/EditCategory", tblCategory));
            }
            else
            {
                tblCategory tblCategory = new tblCategory();
                return(View("Admin/EditCategory", tblCategory));
            }
        }
예제 #3
0
        public ActionResult InsertUpdateCatelogy(tblCategory model)
        {
            var result = new Models.CustomJsonResult();

            try
            {
                if (model != null && !string.IsNullOrEmpty(model.CategoryName))
                {
                    if (model.id > 0)
                    {
                        result.Result  = _catelogyServices.UpdateCatelogy(model);
                        result.Message = int.Parse(result.Result.ToString()) > 0 ? "Update catelogy success!" : "Action had error, please try again!";
                    }
                    else
                    {
                        result.Result  = _catelogyServices.InsertCatelogy(model);
                        result.Message = int.Parse(result.Result.ToString()) > 0 ? "Create new catelogy success!" : "Action had error, please try again!";
                    }
                }
                else
                {
                    result.Result  = 0;
                    result.Message = "Action had error, please try again!";
                }
            }
            catch (Exception ex)
            { }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public IHttpActionResult PuttblCategory(string id, tblCategory tblCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tblCategory.CategoryID)
            {
                return(BadRequest());
            }

            db.Entry(tblCategory).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!tblCategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #5
0
        public long UpdateCatelogy(tblCategory category)
        {
            long result = 0;
            var  key    = "SelectByCatelogyID-" + category.id;

            try
            {
                using (var db = ContextFactory.UsTransportEntities())
                {
                    var _temp = db.tblCategories.Where(x => x.id == category.id).FirstOrDefault();
                    if (_temp != null)
                    {
                        db.Entry(_temp).CurrentValues.SetValues(category);
                        if (db.SaveChanges() > 0)
                        {
                            result = _temp.id;
                            MemoryCache.Default.Remove(key);
                        }
                    }
                    result = category.id;
                }
            }
            catch (Exception ex)
            {
                SELog.WriteLog("CategoryService => UpdateCatelogy", ex);
            }
            return(result);
        }
예제 #6
0
        public ActionResult FilterPostsByCatID(int?id, int?page)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }
            tblCategory category = db.tblCategories.Find(id);

            if (db.tblTags.FirstOrDefault(t => t.Tag_Title.Contains(category.Cat_Name)) != null)
            {
                db.tblTags.FirstOrDefault(t => t.Tag_Title.Contains(category.Cat_Name)).Tag_CountSearch++;
                db.SaveChanges();
            }
            else
            {
                tblTag tag = new tblTag()
                {
                    Tag_Title       = category.Cat_Name,
                    Tag_DateAdd     = DateTime.Now,
                    Tag_CountSearch = 1
                };
                db.tblTags.Add(tag);
                db.SaveChanges();
            }
            ViewBag.Title     = "Tìm kiếm code theo danh mục";
            ViewBag.countPost = db.tblPosts.Where(t => t.Post_Cat == id && t.Post_Active == true && t.Post_Trash == false).Count();
            IPagedList <tblPost> post = db.tblPosts.Where(t => t.Post_Cat == id && t.Post_Active == true && t.Post_Trash == false).OrderByDescending(t => t.Post_DateCreate).ToPagedList(page ?? 1, PAGE_SIZE);

            return(View("Index", post));
        }
예제 #7
0
            /// <summary>
            /// Return Affected Row Or Error If Exist
            /// </summary>
            /// <param name="request">Category Information</param>
            /// <returns>Affected Row Or Error If Exist</returns>
            public static GetCategoryResponse Category(GetCategoryResponse request)
            {
                GetCategoryResponse response = new GetCategoryResponse();

                response.Error = new Handler.ErrorObject();
                try
                {
                    tblCategory Category = new tblCategory()
                    {
                        id         = request.Category.id,
                        name       = request.Category.name,
                        detail     = request.Category.detail,
                        idCategory = request.Category.CategoryID,
                        createDate = request.Category.createDate,
                        upDateDate = DateTime.Now,
                        deleteDate = null,
                        state      = "Active"
                    };

                    var result = CategoryData.Update.Category(Category);
                    if (result.Item1.Error)
                    {
                        response.Error.InfoError(result.Item1);
                    }
                    else
                    {
                        response.Message = result.Item2;
                    }
                }
                catch (Exception ex)
                {
                    response.Error.InfoError(ex);
                }
                return(response);
            }
예제 #8
0
        public tblCategory SelectByCatelogyID(int id)
        {
            tblCategory _item = new tblCategory();

            try
            {
                var    key  = "SelectByCatelogyID-" + id;
                object HTML = MemoryCache.Default.Get(key);
                if (HTML != null)
                {
                    return((tblCategory)HTML);
                }
                else
                {
                    using (var db = ContextFactory.UsTransportEntities())
                    {
                        _item = db.tblCategories.Where(x => x.id == id).FirstOrDefault();
                    }
                    if (_item != null)
                    {
                        MemoryCache.Default.Add(key, _item, DateTimeOffset.UtcNow.AddMinutes(60));
                    }
                }
            }
            catch (Exception ex)
            {
                SELog.WriteLog("CategoryService => SelectByCatelogyID", ex);
            }
            return(_item);
        }
예제 #9
0
    private bool SaveData()
    {
        objCommon = new clsCommon();
        if (objCommon.IsRecordExists("tblCategory", tblCategory.ColumnNames.AppCategory, tblCategory.ColumnNames.AppCategoryID, txtCategoryName.Text, hdnPKID.Value))
        {
            DInfo.ShowMessage("Category Name alredy exits.", Enums.MessageType.Error);
            return(false);
        }
        objCategory = new tblCategory();
        if (!string.IsNullOrEmpty(hdnPKID.Value) && hdnPKID.Value != "")
        {
            objCategory.LoadByPrimaryKey(Convert.ToInt32(hdnPKID.Value));
        }
        else
        {
            objCategory.AddNew();
            objCategory.s_AppCreatedBy  = Session[appFunctions.Session.UserID.ToString()].ToString();
            objCategory.AppDisplayOrder = objCommon.GetNextDisplayOrder("tblCategory", tblCategory.ColumnNames.AppDisplayOrder);
            // objCategory.s_AppCreatedDate = FormatDateString(DateTime.Now.ToString(strInputDateFormat), strInputDateFormat, strOutputDateFormat);
            objCategory.AppCreatedDate = DateTime.Now;
        }

        objCategory.AppCategory = txtCategoryName.Text;
        objCategory.AppIsActive = chkIsActive.Checked;
        objCategory.Save();
        intPkId     = objCategory.AppCategoryID;
        objCategory = null;
        objCommon   = null;
        return(true);
    }
예제 #10
0
        public long UpdateCatelogy(tblCategory category)
        {
            long result = 0;

            try
            {
                using (var db = ContextFactory.UsTransportEntities())
                {
                    var _temp = db.tblCategories.Where(x => x.id == category.id).FirstOrDefault();
                    if (_temp != null)
                    {
                        db.Entry(_temp).CurrentValues.SetValues(category);
                        if (db.SaveChanges() > 0)
                        {
                            result = _temp.id;
                        }
                    }
                    result = category.id;
                }
            }
            catch (Exception ex)
            {
                string e = ex.Message;
            }
            return(result);
        }
예제 #11
0
        public SPResponse ActiveInactiveCategory(int CategoryId)
        {
            tblCategory objcategory = new tblCategory();
            SPResponse  result      = new SPResponse();

            using (var context = new CommonDBContext())
            {
                objcategory = context.tblCategories.Where(x => x.CategoryId == CategoryId).FirstOrDefault();

                if (objcategory.IsActive == true)
                {
                    objcategory.IsActive = false;
                }
                else
                {
                    objcategory.IsActive = true;
                }

                context.tblCategories.AddOrUpdate(objcategory);
                context.SaveChanges();
                result.ResponseCode    = "00";
                result.ResponseMessage = "Category Updated Successfully";
            }
            return(result);
        }
        public async Task <string> AddUpdateCategory(CategoryDomainModel category)
        {
            string status = "";

            if (category.cat_id > 0)
            {
                tblCategory categoryToUpdate = await categoryRepository.SingleOrDefault(c => c.cat_id == category.cat_id);

                if (categoryToUpdate != null)
                {
                    categoryToUpdate.cat_id     = category.cat_id;
                    categoryToUpdate.name       = category.name;
                    categoryToUpdate.mainCat_id = category.mainCat_id;

                    await categoryRepository.Update(categoryToUpdate);

                    status = "updated";
                }
            }
            else
            {
                tblCategory categoryToAdd = new tblCategory();
                categoryToAdd.cat_id     = category.cat_id;
                categoryToAdd.name       = category.name;
                categoryToAdd.mainCat_id = category.mainCat_id;

                await categoryRepository.Insert(categoryToAdd);

                status = "added";
            }
            return(status);
        }
        public IHttpActionResult PosttblCategory(tblCategory tblCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.tblCategories.Add(tblCategory);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (tblCategoryExists(tblCategory.CategoryID))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = tblCategory.CategoryID }, tblCategory));
        }
예제 #14
0
        public IHttpActionResult GettblCategory(int id)
        {
            try
            {
                //tblCategory tblCategory = db.tblCategories.Find(id);
                //if (tblCategory == null)
                //{
                //    return NotFound();
                //}
                //return Ok(tblCategory);
                var data = db.tblCategories.Where(w => w.ID == id).FirstOrDefault();

                if (data == null)
                {
                    return(Ok(new { code = 1, data = "Not found" }));
                }
                else
                {
                    tblCategory model = new tblCategory();
                    model.ID        = data.ID;
                    model.Name      = data.Name;
                    model.Created   = System.DateTime.Now;
                    model.CreatedBy = data.CreatedBy;
                    model.Updated   = System.DateTime.Now;
                    model.UpdatedBy = data.UpdatedBy;
                    model.Active    = Convert.ToBoolean(data.Active);

                    return(Ok(new { code = 0, data = model }));
                }
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
예제 #15
0
        public IHttpActionResult PosttblCategory(tblCategory tblCategory)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var data = db.tblCategories.Where(w => w.Name == tblCategory.Name).FirstOrDefault();

                if (data == null)
                {
                    db.tblCategories.Add(tblCategory);
                    db.SaveChanges();

                    return(Ok(new { code = 0, data = "Category added successfully." }));
                }
                else
                {
                    return(Ok(new { code = 1, data = "Category already exists." }));
                }
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public ActionResult AddCategory(string jsonData)
        {
            SPResponse result      = new SPResponse();
            var        userDetails = (CustomerLoginDetail)Session["UserSession"];
            string     categoryId  = "";

            try
            {
                JavaScriptSerializer json_serializer = new JavaScriptSerializer();
                json_serializer.MaxJsonLength = int.MaxValue;
                object[]    objData     = (object[])json_serializer.DeserializeObject(jsonData);
                tblCategory objcategory = new tblCategory();
                foreach (Dictionary <string, object> item in objData)
                {
                    objcategory.CategoryName = Convert.ToString(item["CategoryNm"]);
                    objcategory.CreatedBy    = userDetails.LoginId;
                    objcategory.CreatedDate  = DateTime.Now;
                    categoryId           = Convert.ToString(item["CategoryId"]);
                    objcategory.IsActive = Convert.ToBoolean(item["IsActive"]);
                    if (categoryId != "")
                    {
                        objcategory.CategoryId = Convert.ToInt32(categoryId);
                    }
                    else
                    {
                    }
                }
                result = COR.AddCategory(objcategory);
            }
            catch (Exception ex)
            {
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public ActionResult DeleteCategoryConfirmed(int id)
        {
            tblCategory categoryModel = db.tblCategory.Find(id);

            db.tblCategory.Remove(categoryModel);
            db.SaveChanges();
            return(RedirectToAction("Category"));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            tblCategory tblCategory = db.tblCategories.Find(id);

            db.tblCategories.Remove(tblCategory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #19
0
        public void AddCategory(CategoryModel category)
        {
            tblCategory objtblCategory = new tblCategory();

            objtblCategory.Caregory_Name = category.CategoryName;
            dbentity.tblCategories.Add(objtblCategory);
            dbentity.SaveChanges();
        }
예제 #20
0
        public JsonResult AJXUpdateForm()
        {
            int id = Request.Form["updateID"] != null?int.Parse(Request.Form["updateID"]) : -1;

            tblCategory item = _catelogyServices.SelectByCatelogyID(id);

            return(Json(RenderPartialViewToString("_CatelogyDetailForm", item), JsonRequestBehavior.AllowGet));
        }
예제 #21
0
        public ActionResult InsertCategory()
        {
            if (Session["UserID"] == null && Session["UserName"] == null)
            {
                return(RedirectToAction("Login", "Login"));
            }

            try
            {
                tblCategory newCat = new tblCategory();
                newCat.CategoryName = Request.Form["CategoryName"];

                if (ModelState.IsValid)
                {
                    int              fileSize = 0;
                    string           fileName = string.Empty;
                    string           mimeType = string.Empty;
                    System.IO.Stream fileContent;

                    if (Request.Files.Count > 0)
                    {
                        HttpPostedFileBase file = Request.Files[0];

                        fileSize    = file.ContentLength;
                        fileName    = file.FileName;
                        mimeType    = file.ContentType;
                        fileContent = file.InputStream;


                        if (mimeType.ToLower() != "image/jpeg" && mimeType.ToLower() != "image/jpg" && mimeType.ToLower() != "image/png")
                        {
                            return(Json(new { Formatwarning = true, message = "Profile pic format must be JPEG or JPG or PNG." }, JsonRequestBehavior.AllowGet));
                        }

                        #region Save And compress file
                        //To save file, use SaveAs method
                        file.SaveAs(Server.MapPath("~/CategoryImages/") + fileName);
                        if (!ImageProcessing.InsertImages(Server.MapPath("~/CategoryImages/") + fileName))
                        {
                            return(Json(new { success = false, message = "Error occur while uploading image." }, JsonRequestBehavior.AllowGet));
                        }
                        #endregion
                    }
                    newCat.CategoryImage = fileName;

                    newCat.CreatedDate = DateTime.Now;
                    db.tblCategories.Add(newCat);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, message = "Record Not inserted" }, JsonRequestBehavior.AllowGet));
            }


            return(Json(new { success = true, message = "Record inserted" }, JsonRequestBehavior.AllowGet));
        }
예제 #22
0
        void Guncelle()
        {
            tblCategory cat = _db.tblCategories.First(x => x.ID == _secimId);

            cat.CategoryName = txtCname.Text;
            _db.SubmitChanges();
            _m.Guncelle(true);
            Temizle();
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            tblCategory tblcategory = await db.tblCategories.FindAsync(id);

            db.tblCategories.Remove(tblcategory);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "CATEGORY_ID,CATEGORY_NAME")] tblCategory aobjtblCategory)
 {
     if (ModelState.IsValid)
     {
         db.sp_Update_tblCategory(aobjtblCategory.CATEGORY_ID, aobjtblCategory.CATEGORY_NAME);
         return(RedirectToAction("AllCategoryList"));
     }
     return(View(aobjtblCategory));
 }
예제 #25
0
        public ActionResult Delete(int id)
        {
            tblCategory tbl = db.tblCategories.Where(a => a.CategoryId == id).FirstOrDefault();

            db.tblCategories.Remove(tbl);
            db.SaveChanges();

            return(Json(new { success = true, message = "Deleted Sucessfully" }, JsonRequestBehavior.AllowGet));
        }
예제 #26
0
 public ActionResult Delete(int id)
 {
     using (KantipurDBEntities db = new KantipurDBEntities())
     {
         tblCategory sm = db.tblCategories.Where(x => x.CategoryId == id).FirstOrDefault();
         db.tblCategories.Remove(sm);
         db.SaveChanges();
         return(Json(new { success = true, message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet));
     }
 }
예제 #27
0
 public ActionResult Create([Bind(Include = "CategoryId,Name")] tblCategory Category)
 {
     if (ModelState.IsValid)
     {
         db.tblCategories.Add(Category);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(Category));
 }
예제 #28
0
        public tblCategory GetCategoryById(int CategoryId)
        {
            tblCategory objcategory = new tblCategory();

            using (var context = new CommonDBContext())
            {
                objcategory = context.tblCategories.Where(x => x.CategoryId == CategoryId).FirstOrDefault();
            }
            return(objcategory);
        }
예제 #29
0
        //GET: Category/Edit/{id}

        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tblCategory Category = db.tblCategories.Find(id);

            return(View(Category));
        }
예제 #30
0
 public ActionResult Edit([Bind(Include = "CategoryId, Name")] tblCategory Category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(Category).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(Category));
 }
예제 #31
0
 public ActionResult CategoriesEdit(tblCategory tblCategory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tblCategory).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Categories");
     }
     return View(tblCategory);
 }