Example #1
0
 public ActionResult CreateEdit(TypeBusViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (TypeBusDataAccess.Update(model))
             {
                 return(Json(new { success = true, message = "Success" }, JsonRequestBehavior.AllowGet));
             }
             else
             {
                 return(Json(new { success = false, message = TypeBusDataAccess.Message }, JsonRequestBehavior.AllowGet));
             }
         }
         else
         {
             return(Json(new { success = false, message = "Lengkapi isi form nya" }, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception ex)
     {
         return(Json(new { success = false, ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }
Example #2
0
        public static TypeBusViewModel GetById(int id)
        {
            TypeBusViewModel result = new TypeBusViewModel();

            using (var db = new FleetManagementContext())
            {
                result = (from tb in db.MstTypeBus
                          join mb in db.MstMerkBus
                          on tb.MerkId equals mb.MerkId
                          where tb.Id == id
                          select new TypeBusViewModel
                {
                    Id = tb.Id,
                    MerkId = tb.MerkId,
                    MerkName = mb.Description,
                    TypeId = tb.TypeId,
                    Description = tb.Description,
                    IsActive = tb.IsActive,
                    CreatedBy = tb.CreatedBy,
                    Created = tb.Created,
                    ModifiedBy = tb.ModifiedBy,
                    Modified = tb.Modified
                }).FirstOrDefault();
            }
            return(result);
        }
Example #3
0
        public static bool Update(TypeBusViewModel model)
        {
            bool result = true;

            try
            {
                using (var db = new FleetManagementContext())
                {
                    if (model.Id == 0)
                    {
                        MstTypeBu typebus = new MstTypeBu();
                        typebus.MerkId      = model.MerkId;
                        typebus.TypeId      = model.TypeId;
                        typebus.Description = model.Description;
                        typebus.IsActive    = model.IsActive;
                        typebus.CreatedBy   = model.CreatedBy;
                        typebus.Created     = model.Created;
                        typebus.ModifiedBy  = model.ModifiedBy;
                        typebus.Modified    = model.Modified;
                        db.MstTypeBus.Add(typebus);
                        db.SaveChanges();
                    }
                    else
                    {
                        MstTypeBu typebus = db.MstTypeBus.Where(o => o.Id == model.Id).FirstOrDefault();
                        if (typebus != null)
                        {
                            typebus.MerkId      = model.MerkId;
                            typebus.TypeId      = model.TypeId;
                            typebus.Description = model.Description;
                            typebus.IsActive    = model.IsActive;
                            typebus.CreatedBy   = model.CreatedBy;
                            typebus.Created     = model.Created;
                            typebus.ModifiedBy  = model.ModifiedBy;
                            typebus.Modified    = model.Modified;
                            db.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Message = ex.Message;
                result  = false;
            }
            return(result);
        }
Example #4
0
 public ActionResult Edit(TypeBusViewModel model)
 {
     return(CreateEdit(model));
 }