/// <summary> /// Cập nhật category /// </summary> /// <param name="category"></param> /// <param name="userName"></param> /// <returns></returns> public object UpdateCategory(MNG_Category category, string userName) { #region VALIDATE MNG_Category cate = dbContext.MNG_Category.Where(x => !x.IsDeleted && x.CatID == category.CatID).FirstOrDefault(); if (cate == null) { return(MP_AjaxError.NotFound); //Không tìm thấy } if (dbContext.MNG_Category.Any(x => !x.IsDeleted && x.CatID != category.CatID && x.CatCode == category.CatCode)) { return(MP_AjaxError.Exits);//Tồn tại CatCode } #endregion #region HANDLER try { cate.CatCode = category.CatCode; cate.CatName = category.CatName; cate.ExpandProperties = category.ExpandProperties; cate.UpdatedBy = userName; cate.UpdatedDate = DateTime.Now; dbContext.SaveChanges(); return(MP_AjaxError.OK); } catch (Exception ex) { return(ex.Message); } #endregion }
/// <summary> /// Thêm mới category /// </summary> /// <param name="category"></param> /// <returns></returns> public object AddNewCategory(MNG_Category category, string userName) { try { MNG_Category obj = new MNG_Category { CatName = category.CatName, CatTypeCode = category.CatTypeCode, CatCode = category.CatCode, CatID = Guid.NewGuid(), CreatedBy = userName, CreatedDate = DateTime.Now, ExpandProperties = category.ExpandProperties, IsDeleted = false, OrderBy = 0, Value = string.Empty }; dbContext.MNG_Category.Add(obj); dbContext.SaveChanges(); return(MP_AjaxError.OK); } catch (System.Exception ex) { return(ex.Message); } }
public HttpResponseMessage UpdateCategory(MNG_Category cate) { #region VALIDATE if (cate == null || string.IsNullOrEmpty(cate.CatTypeCode) || string.IsNullOrEmpty(cate.CatCode) || string.IsNullOrEmpty(cate.CatName)) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "NoCategory")); } #endregion return(Request.CreateResponse(HttpStatusCode.OK, new { value = _categoryServices.UpdateCategory(cate, this.RequestContext.Principal.Identity.Name) })); }
/// <summary> /// Cập nhật isdeleted = true cho Category /// </summary> /// <param name="cat"></param> /// <param name="userName"></param> /// <returns></returns> public object DeleteCategory(MNG_Category cat) { try { MNG_Category _cat = dbContext.MNG_Category.Where(x => x.CatCode == cat.CatCode && !x.IsDeleted).FirstOrDefault(); if (_cat != null) { _cat.IsDeleted = true; dbContext.SaveChanges(); return(MP_AjaxError.OK); } else { return(MP_AjaxError.NotFound); } } catch (System.Exception ex) { return(ex.Message); } #endregion }
public HttpResponseMessage AddNewCategory(MNG_Category category) { return(Request.CreateResponse(HttpStatusCode.OK, new { value = _categoryServices.AddNewCategory(category, this.RequestContext.Principal.Identity.Name) })); }
public HttpResponseMessage DeleteCategory(MNG_Category cat) { return(Request.CreateResponse(HttpStatusCode.OK, new { status = _categoryServices.DeleteCategory(cat) })); }