Ejemplo n.º 1
0
        public static AnggotaViewModel GetById(int id)
        {
            AnggotaViewModel result = new AnggotaViewModel();

            using (var db = new PerpusContext())
            {
                result = (from ag in db.Anggota
                          //join pdf in db.Pendaftaran
                          //on ag.KodeAnggota equals pdf.KodeKartu
                          where ag.Id == id
                          select new AnggotaViewModel
                {
                    Id = ag.Id,
                    KodeAnggota = ag.KodeAnggota,
                    Nama = ag.Nama,
                    Alamat = ag.Alamat,
                    Email = ag.Email,
                    Telepon = ag.Telepon
                              //CreatedBy = ag.CreatedBy,
                              //Created = ag.Created,
                              //ModifiedBy = ag.ModifiedBy,
                              //Modified = ag.Modified
                }).FirstOrDefault();
            }
            return(result);
        }
Ejemplo n.º 2
0
 public ActionResult CreateEdit(AnggotaViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (AnggotaDataAccess.Update(model))
             {
                 return(Json(new { success = true, message = "Success" }, JsonRequestBehavior.AllowGet));
             }
             else
             {
                 return(Json(new { success = false, message = AnggotaDataAccess.Message }, JsonRequestBehavior.AllowGet));
             }
         }
         else
         {
             return(Json(new { success = false, message = "Please full fill required fields!" }, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception ex)
     {
         return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }
Ejemplo n.º 3
0
        public static bool Update(AnggotaViewModel model)
        {
            bool result = true;

            try
            {
                using (var db = new PerpusContext())
                {
                    if (model.Id == 0)
                    {
                        Anggota anggota = new Anggota
                        {
                            KodeAnggota = model.KodeAnggota,
                            Nama        = model.Nama,
                            Alamat      = model.Alamat,
                            Email       = model.Email,
                            Telepon     = model.Telepon
                                          //CreatedBy = model.CreatedBy,
                                          //Created = model.Created,
                                          //ModifiedBy = model.Modified,
                                          //Modified = model.Modified
                        };
                        db.Anggota.Add(anggota);
                        db.SaveChanges();
                    }
                    else
                    {
                        Anggota anggota = db.Anggota.Where(o => o.Id == model.Id).FirstOrDefault();
                        if (anggota != null)
                        {
                            anggota.KodeAnggota = model.KodeAnggota;
                            anggota.Nama        = model.Nama;
                            anggota.Alamat      = model.Alamat;
                            anggota.Email       = model.Email;
                            anggota.Telepon     = model.Telepon;
                            //anggota.CreatedBy = model.CreatedBy;
                            //anggota.Created = model.Created;
                            //anggota.ModifiedBy = model.ModifiedBy;
                            //anggota.Modified = model.Modified;
                            db.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Message = ex.Message;
                result  = false;
            }
            return(result);
        }
Ejemplo n.º 4
0
        public AnggotaTest()
        {
            context                 = new ViewModels.AnggotaViewModel(new Library.DTO.user());
            context.Agama           = Library.Kepercayaan.Hindu;
            context.Alamat          = "Mana";
            context.AsalSekolah     = "Manakek";
            context.AsalUniversitas = "AuAh";

            context.IdUnitKerja  = "01";
            context.JenisKelamin = Library.Gender.Wanita;
            context.Nama         = "Amrin";
            context.TempatLahir  = "Buton";
            context.TglLahir     = DateTime.Now;
        }
Ejemplo n.º 5
0
 public ActionResult Edit(AnggotaViewModel model)
 {
     return(CreateEdit(model));
 }