public int Update(YearBatchViewModel yvm)
        {
            tblYearBatch tb       = _db.tblYearBatches.Where(y => y.YearBatchId == yvm.Id).FirstOrDefault();
            var          yearName = tb.Year_Batch;

            tb.Year_Batch = yvm.Year_Batch;
            _db.SaveChanges();
            tblMainLog tml       = new tblMainLog();
            var        principal = System.Security.Claims.ClaimsPrincipal.Current;
            string     Name      = principal.FindFirst(ClaimsIdentity.DefaultNameClaimType).Value;

            str             = "YearBatch Updated from '" + yearName + "' " + "to '" + yvm.Year_Batch + "' " + "by Admin";
            tml.Description = str;
            tml.AdminName   = Name;
            tml.Date        = System.DateTime.Now;
            tml.EntityId    = 5;
            tml.ItemId      = tb.YearBatchId;
            _db.tblMainLogs.Add(tml);
            return(_db.SaveChanges());
        }
        public HttpResponseMessage Post([Bind(Include = "Year_Batch,Model")] YearBatchViewModel yvm)
        {
            //AssignmentManagementSystemEntities db = new AssignmentManagementSystemEntities();
            string message  = "New Year/Batch Added Successfully";
            bool   isexists = yearDB.CheckYearbatch(yvm.Year_Batch);

            if (isexists)
            {
                ModelState.AddModelError("Year_Batch", "Year/Batch Already Exist");
            }
            if (ModelState.IsValid)
            {
                yearDB.Add(yvm);
                return(Request.CreateResponse(HttpStatusCode.OK, message));
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
        public int Add(YearBatchViewModel yvm)
        {
            tblYearBatch tb = new tblYearBatch();

            tb.Year_Batch = yvm.Year_Batch;
            _db.tblYearBatches.Add(tb);
            _db.SaveChanges();
            tblMainLog tml       = new tblMainLog();
            var        principal = System.Security.Claims.ClaimsPrincipal.Current;
            string     Name      = principal.FindFirst(ClaimsIdentity.DefaultNameClaimType).Value;

            str             = "New Yearbatch '" + yvm.Year_Batch + "' " + "Added by Admin";
            tml.Description = str;
            tml.AdminName   = Name;
            tml.Date        = System.DateTime.Now;
            tml.EntityId    = 5;
            tml.ItemId      = tb.YearBatchId;
            _db.tblMainLogs.Add(tml);
            return(_db.SaveChanges());
        }
        public HttpResponseMessage Put([Bind(Include = "Year_Batch,Model")] YearBatchViewModel yvm)
        {
            AssignmentManagementSystemEntities db = new AssignmentManagementSystemEntities();
            var          year     = yearDB.ListAll().Find(y => y.Id.Equals(yvm.Id));
            string       message  = "Year/Batch Updated Successfully";
            tblYearBatch tb       = db.tblYearBatches.Where(y => y.YearBatchId == yvm.Id).FirstOrDefault();
            bool         isexists = yearDB.CheckYearbatch(yvm.Year_Batch);

            if (isexists)
            {
                if (tb.Year_Batch == yvm.Year_Batch)
                {
                    if (ModelState.IsValid)
                    {
                        yearDB.Update(yvm);
                        return(Request.CreateResponse(HttpStatusCode.OK, message));
                    }
                    else
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
                    }
                }
                else
                {
                    ModelState.AddModelError("Year_Batch", "Year/Batch Already Exist");
                }
            }

            if (ModelState.IsValid)
            {
                yearDB.Update(yvm);
                return(Request.CreateResponse(HttpStatusCode.OK, message));
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }