Example #1
0
        public static bool Update(ServiceViewModel model)
        {
            bool result = true;

            try
            {
                using (var db = new FleetManagementContext())
                {
                    if (model.Id == 0)
                    {
                        MstService service = new MstService();
                        service.ServiceId   = model.ServiceId;
                        service.Description = model.Description;
                        service.IsActive    = model.IsActive;
                        service.CreatedBy   = model.CreatedBy;
                        service.Created     = model.Created;
                        service.ModifiedBy  = model.ModifiedBy;
                        service.Modified    = model.Modified;
                        db.MstServices.Add(service);
                        db.SaveChanges();
                    }
                    else
                    {
                        MstService service = db.MstServices.Where(o => o.Id == model.Id).FirstOrDefault();
                        if (service != null)
                        {
                            service.ServiceId   = model.ServiceId;
                            service.Description = model.Description;
                            service.IsActive    = model.IsActive;
                            service.CreatedBy   = model.CreatedBy;
                            service.Created     = model.Created;
                            service.ModifiedBy  = model.ModifiedBy;
                            service.Modified    = model.Modified;
                            db.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Message = ex.Message;
                result  = false;
            }
            return(result);
        }
Example #2
0
        public static bool Delete(int id)
        {
            bool result = true;

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