public Person Add(Person person)
        {
            using (var Transaction = db.Database.BeginTransaction())
            {
                try
                {
                    db.Person.Add(person);
                    db.SaveChanges();

                    var institute = new Institute()
                    {
                        Name     = "Institute Name",
                        PersonID = person.Id
                    };

                    db.Institute.Add(institute);
                    db.SaveChanges();

                    person.InstituteID = institute.Id;
                    db.Entry(person).Property(x => x.InstituteID).IsModified = true;
                    db.SaveChanges();

                    Transaction.Commit();
                }
                catch (Exception ex)
                {
                    Transaction.Rollback();
                }
            }
            return(person);
        }
Exemple #2
0
 public T Add(T entity, int created_by = 0)
 {
     ds.Add(entity);
     //TrySetProperty(entity, "created_by", created_by);
     //TrySetProperty(entity, "update_date", DateTime.UtcNow);
     db.SaveChanges();
     return(entity);
 }
        public ActionResult Create([Bind(Include = "Id,Name,AddressID,Deleted")] Address address)
        {
            if (ModelState.IsValid)
            {
                db.Address.Add(address);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AddressID = new SelectList(db.Address, "Id", "Name", address.AddressID);
            return(View(address));
        }
Exemple #4
0
        public ClassSubject Add(ClassSubjectVM entity)
        {
            var instuteID = Convert.ToInt32(Membership.GetUser().PasswordQuestion);

            var classsubject = new ClassSubject()
            {
                InstituteID  = instuteID,
                ClassId      = entity.ClassId,
                SubjectNames = entity.SubjectNames
            };

            using (var Transaction = db.Database.BeginTransaction())
            {
                try
                {
                    db.ClassSubject.Add(classsubject);
                    db.SaveChanges();

                    if (entity.SubjectBooks != null)
                    {
                        foreach (var item in entity.SubjectBooks)
                        {
                            if (!string.IsNullOrWhiteSpace(item.Name))
                            {
                                item.ClassSubjectID = classsubject.Id;
                                db.SubjectBook.Add(item);
                            }
                        }
                        db.SaveChanges();
                    }
                    Transaction.Commit();
                }
                catch (Exception ex)
                {
                    Transaction.Rollback();
                }
            }

            return(classsubject);
        }
 public void Update(Institute entity)
 {
     db.Institute.Attach(entity);
     db.Entry(entity).Property(x => x.Address).IsModified = true;
     db.Entry(entity).Property(x => x.Email).IsModified   = true;
     db.Entry(entity).Property(x => x.Name).IsModified    = true;
     db.Entry(entity).Property(x => x.Phone).IsModified   = true;
     if (entity.Logo != null)
     {
         db.Entry(entity).Property(x => x.Logo).IsModified = true;
     }
     db.SaveChanges();
     //if (entity.Logo == null)
     //    rep.Update(entity, x => x.Address, x => x.Email, x => x.Name, x => x.Phone);
     //else
     //    rep.Update(entity, x => x.Address, x => x.Email, x => x.Name, x => x.Phone, x => x.Logo);
 }
Exemple #6
0
 public ActionResult Edit([Bind(Include = "Id,TotalMarks")] ClassExams ClassExams)
 {
     if (ModelState.IsValid)
     {
         var        instuteID = Convert.ToInt32(Membership.GetUser().PasswordQuestion);
         ClassExams Exams     = db.ClassExams.Find(ClassExams.Id);
         if (Exams == null || Convert.ToInt32(Exams.InstituteID) != instuteID || Exams.Deleted == true)
         {
             return(HttpNotFound());
         }
         if (!rep.CheckIfExists(Exams.ClassID, Exams.ExamNamesID))
         {
             ModelState.AddModelError(string.Empty, "Data Doesn't Exists");
             return(View(ClassExams));
         }
         Exams.TotalMarks      = ClassExams.TotalMarks;
         db.Entry(Exams).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(ClassExams));
 }
Exemple #7
0
 public void Update(ClassExams entity)
 {
     db.ClassExams.Attach(entity);
     db.Entry(entity).Property(x => x.TotalMarks).IsModified = true;
     db.SaveChanges();
 }