Ejemplo n.º 1
0
        public ActionResult Add(Category objCategory)
        {
            objCategory.AddedBy = "Admin";
            objCategory.AddedOn = DateTime.Now;
            int i = cDAl.AddCategory(objCategory);

            if (i == 0)
            {
                ViewBag.Message = "Data Added Successfully";
            }
            return(View(objCategory));
        }
Ejemplo n.º 2
0
        public bool AddCategory(Category category)
        {
            List <Category> categories = GetCategories();

            foreach (var item in categories)
            {
                if (item.Name == category.Name)
                {
                    return(false);
                }
            }
            return(categoriesDal.AddCategory(category));
        }
        public HttpResponseMessage AddCategory(Category category)
        {
            ResponseMessage <CategoryModel> objResponseData = new ResponseMessage <CategoryModel>();

            try
            {
                CategoryModel categoryModel = new CategoryModel();
                if (objCategoryDAL.GetAllCategories().ToList().Any(cat => cat.CategoryName != category.CategoryName))
                {
                    Category newCategory = objCategoryDAL.AddCategory(category);
                    if (newCategory.CategoryId > 0)
                    {
                        //mapping
                        categoryModel   = Mapper.Map <Category, CategoryModel>(newCategory, categoryModel);
                        objResponseData = ResponseHandler <CategoryModel> .CreateResponse(objResponseData, "Successfully Added A New Category.", categoryModel, HttpStatusCode.OK);
                    }
                    else
                    {
                        //mapping
                        categoryModel   = Mapper.Map <Category, CategoryModel>(category, categoryModel);
                        objResponseData = ResponseHandler <CategoryModel> .CreateResponse(objResponseData, "Can't Add This Category.", HttpStatusCode.Conflict);
                    }
                }
                else  // category name is already present
                {
                    //mapping
                    categoryModel   = Mapper.Map <Category, CategoryModel>(category, categoryModel);
                    objResponseData = ResponseHandler <CategoryModel> .CreateResponse(objResponseData, "This category is already available.", categoryModel, HttpStatusCode.Conflict);
                }
            }
            catch (System.Exception ex)
            {
                objErrorLogger.ErrorLog(ex);
                objResponseData = ResponseHandler <CategoryModel> .CreateErrorResponse(objResponseData);
            }
            return(Request.CreateResponse(objResponseData.StatusCode, objResponseData));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 /// <param name="entity"></param>
 public void AddCategory(Category entity)
 {
     service.AddCategory(entity);
 }
Ejemplo n.º 5
0
 public bool AddCategory(string CategoryName)
 {
     return(categoryDAL.AddCategory(CategoryName));
 }
Ejemplo n.º 6
0
 public static void AddCategory(Category category)
 {
     CategoryDAL.AddCategory(category);
 }
Ejemplo n.º 7
0
 public void AddCategory(Category category)
 {
     _db.AddCategory(category);
 }