Beispiel #1
0
        public async Task <ReturnBook> UpdateAsync(ReturnBook model)
        {
            _context.Entry(model).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(model);
        }
 public bool Update(Company company)
 {
     //_db.Companies.Add(new Company() { Address = company.Address, CompanyName = company.CompanyName, Remark = company.Remark });
     _db.Entry(company).State = EntityState.Modified;
     return(_db.SaveChanges() > 0 ? true : false);
     //return compnay;
 }
        public ActionResult AddOrEditAttendance(Attendance attendance)
        {
            using (LMSContext db = new LMSContext())
            {
                if (attendance.ID == 0)
                {
                    var newAtendance = new Attendance();
                    newAtendance.Date   = DateTime.Now;
                    newAtendance.Remark = "test";

                    var student = db.Students.ToList().FirstOrDefault();
                    newAtendance.Student = student;

                    db.Attendances.Add(newAtendance);
                    db.SaveChanges();
                    return(Json(new { success = true, message = "Записът е успешен." }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    db.Entry(attendance).State = EntityState.Modified;
                    db.SaveChanges();
                    return(Json(new { success = true, message = "Редакцията е успешна." }, JsonRequestBehavior.AllowGet));
                }
            }
        }
Beispiel #4
0
        public async Task <LatePayment> UpdateAsync(LatePayment model)
        {
            _context.Entry(model).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(model);
        }
Beispiel #5
0
 public virtual void Delete(TEntity entityToDelete)
 {
     if (context.Entry(entityToDelete).State == EntityState.Detached)
     {
         dbSet.Attach(entityToDelete);
     }
     dbSet.Remove(entityToDelete);
 }
Beispiel #6
0
 public async Task <List <ReserveBook> > UpdateAsync(List <ReserveBook> model)
 {
     foreach (var item in model)
     {
         _context.Entry(item).State = EntityState.Modified;
         await _context.SaveChangesAsync();
     }
     return(model);
 }
 public ActionResult AddOrEditSubjectGrade(SubjectGrade subgr)
 {
     using (LMSContext db = new LMSContext())
     {
         if (subgr.ID == 0)
         {
             db.SubjectGrades.Add(subgr);
             db.SaveChanges();
             return(Json(new { success = true, message = "Записът е успешен." }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             db.Entry(subgr).State = EntityState.Modified;
             db.SaveChanges();
             return(Json(new { success = true, message = "Редакцията е успешна." }, JsonRequestBehavior.AllowGet));
         }
     }
 }
Beispiel #8
0
        public int UpdateUser(User user)
        {
            var dbuser = _db.Users.Where(u => u.UserId == user.UserId).FirstOrDefault();

            if (dbuser != null)
            {
                _db.Entry(user).State = EntityState.Modified;
            }
            //foreach (var item in user.Roles)
            //{
            //    var roleEntry = user.Roles.Select(x=>x.RoleId==user.).SingleOrDefault(r => r.RoleId == user.UserId);
            //    if (roleEntry != null)
            //    {
            //        _db.UserRoles.Remove(roleEntry);
            //        _db.SaveChanges();
            //    }
            //    _db.UserRoles.Add(item);
            return(_db.SaveChanges());
        }
Beispiel #9
0
        public async Task <Book> UpdateAsync(Book model)
        {
            var             bookCategories = _context.Categories.ToList <Category>();;
            List <Category> Categories     = new List <Category>();

            foreach (Category Category in model.Categories)
            {
                var InBookCategory = bookCategories.Where(c => c.Name == Category.Name).FirstOrDefault();
                if (InBookCategory != null)
                {
                    Categories.Add(InBookCategory);
                }
                else
                {
                    Categories.Add(Category);
                }
            }
            model.Categories = Categories;
            var           bookAuthors = _context.Authors.ToList <Author>();
            List <Author> Authors     = new List <Author>();

            foreach (Author Author in model.Authors)
            {
                var InBookAuthor = bookAuthors.Where(c => c.Name == Author.Name).FirstOrDefault();
                if (InBookAuthor != null)
                {
                    Authors.Add(InBookAuthor);
                }
                else
                {
                    Authors.Add(Author);
                }
            }
            model.Authors = Authors;

            _context.Entry(model).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(model);
        }