コード例 #1
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);
        }
コード例 #2
0
        public static bool Delete(int id)
        {
            bool result = true;

            try
            {
                using (var db = new FleetManagementContext())
                {
                    MstTypeBu typebus = db.MstTypeBus.Where(o => o.Id == o.Id).FirstOrDefault();
                    if (typebus != null)
                    {
                        db.MstTypeBus.Remove(typebus);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                Message = ex.Message;
                result  = false;
            }
            return(result);
        }