public void Delete(BatchTypeView batchTypeView)
 {
     using (var rep = new BatchTypeRepository())
     {
         rep.Delete(ConvertBatchType(batchTypeView));
     }
 }
        public ActionResult EditBatchType(BatchTypeView model)
        {
            if (ModelState.IsValid)
            {

                _db.Update(model);
                return RedirectToAction("GetAllBatchType");
            }
            return View(model);
        }
        public void Insert(BatchTypeView batchTypeView)
        {
            using (var rep = new BatchTypeRepository())
            {
                var batchtype = new BatchType
                {

                    BatchTypeDesc = batchTypeView.BatchTypeDesc,
                    BatchTypeid = batchTypeView.BatchTypeid
                };
                rep.Insert(batchtype);
            }
        }
        public void Update(BatchTypeView batchTypeView)
        {
            using (var batchtyperepo = new BatchTypeRepository())
            {
                BatchType batchtype = batchtyperepo.GetById(batchTypeView.BatchTypeid);
                if (batchtype != null)
                {

                    batchtype.BatchTypeid = batchTypeView.BatchTypeid;

                    batchtype.BatchTypeDesc = batchTypeView.BatchTypeDesc;
                   batchtyperepo.Update(batchtype);
                }
            }
        }
        public BatchTypeView GetBatchTypeById(int id)
        {
            using (var batchtyperepo = new BatchTypeRepository())
            {
                BatchType batchtype = batchtyperepo.GetById(id);
                var batchtypeView = new BatchTypeView();
                if (batchtype != null)
                {
                    batchtypeView.BatchTypeDesc = batchtype.BatchTypeDesc;

                    batchtypeView.BatchTypeid = batchtype.BatchTypeid;
                }
                return batchtypeView;
            }
        }
        public ActionResult AddBatchType(BatchTypeView model)
        {
            // BatchType _dbb=new BatchType();
            var titleobj = _db.GetAllBatchTypes().Find(t => t.BatchTypeDesc.StartsWith(model.BatchTypeDesc));
            //int countrec = _db.GetAllBatchTypes().Count;
            //if (countrec > 5)
              //  {
            if (titleobj != null)
            {
                ViewBag.Exist = "Batch Of " + model.BatchTypeDesc + "Already Exists, Please Enter Anther One";
                return View(model);
            }

              //  }
            _db.Insert(model);
            return RedirectToAction("GetAllBatchType");
        }
        private static BatchType ConvertBatchType(BatchTypeView batchTypeView)
        {
            var batchtype = new BatchType
            {
                BatchTypeid = batchTypeView.BatchTypeid,
                BatchTypeDesc = batchTypeView.BatchTypeDesc

            };
            return batchtype;
        }