public ActionResult ItemAdd(ItemsDTO model) { CategoryBL category = new CategoryBL(); MeasureBL measure = new MeasureBL(); List <CategoryDTO> categorydt = new List <CategoryDTO>(); List <MeasureDTO> measuredt = new List <MeasureDTO>(); category.SearchList(out categorydt); measure.SearchList(out measuredt); ViewBag.CategoryList = categorydt; ViewBag.MeasureList = measuredt; ItemBL bl = new ItemBL(); if (ModelState.IsValid) { int count = bl.CheckCode(model); if (count > 0) { TempData["Error"] = "Code already exists"; TempData["Success"] = ""; return(View(model)); } else { if (model.discontinued_datetime.IsNotNullOrEmpty() == true) { string datetime = DateTime.Parse(model.discontinued_datetime).ToString("yyyy-MM-dd HH:mm:ss"); model.discontinued_datetime = datetime; } model.created_by = 0; model.updated_by = 0; int equal = bl.InsertData(model); if (equal == 1) { TempData["Error"] = "Insert badly"; TempData["Success"] = ""; return(View(model)); } else { TempData["Error"] = ""; TempData["Success"] = "Insert successfully"; return(RedirectToAction("ItemAdd")); } } } else { return(View(model)); } }