示例#1
0
 public static IQueryable <Activity> GetActivities(Activity searchCrit)
 {
     try
     {
         CarWorkshopModelContext dc = new CarWorkshopModelContext();
         var result = from el in dc.Activity
                      where
                      String.IsNullOrEmpty(searchCrit.description) || el.description.StartsWith(searchCrit.description)
                      &&
                      (searchCrit.id_personel == null) || (el.id_personel == searchCrit.id_personel)
                      &&
                      String.IsNullOrEmpty(searchCrit.status) || el.status.StartsWith(searchCrit.status)
                      &&
                      String.IsNullOrEmpty(searchCrit.result) || el.result.StartsWith(searchCrit.result)
                      &&
                      (searchCrit.date_fin_cancel == null) || (el.date_fin_cancel == searchCrit.date_fin_cancel)
                      &&
                      (searchCrit.date_request == null) || (el.date_request == searchCrit.date_request)
                      &&
                      String.IsNullOrEmpty(searchCrit.act_type) || el.act_type.StartsWith(searchCrit.act_type)
                      &&
                      (searchCrit.seq_no == null) || (el.seq_no == searchCrit.seq_no)
                      select el;
         return(result);
     }
     catch (System.Data.Entity.Core.EntityException e)
     {
         throw new ServiceException("Database connection error!");
     }
 }
示例#2
0
 public static void UpdateActivity(Activity request)
 {
     try
     {
         CarWorkshopModelContext dc = new CarWorkshopModelContext();
         var result = (from el in dc.Activity
                       where
                       el.id_request == request.id_request
                       select el).SingleOrDefault();
         if (result == null)
         {
             return;
         }
         result.date_fin_cancel = request.date_fin_cancel;
         result.date_request    = request.date_request;
         result.description     = request.description;
         result.id_activity     = request.id_activity;
         result.id_personel     = request.id_personel;
         result.result          = request.result;
         result.status          = request.status;
         result.act_type        = request.act_type;
         result.seq_no          = request.seq_no;
         dc.SaveChanges();
     }
     catch (System.Data.Entity.Core.EntityException e)
     {
         throw new ServiceException("Database connection error!");
     }
 }
示例#3
0
 public static IQueryable <DataLayer.Object> GetObjects(DataLayer.Object searchCrit)
 {
     try
     {
         CarWorkshopModelContext dc = new CarWorkshopModelContext();
         var result = from el in dc.Object
                      where
                      String.IsNullOrEmpty(searchCrit.body_type) || el.body_type.StartsWith(searchCrit.body_type)
                      &&
                      (searchCrit.id_client == null) || (el.id_client == searchCrit.id_client)
                      &&
                      String.IsNullOrEmpty(searchCrit.manufacturer) || el.manufacturer.StartsWith(searchCrit.manufacturer)
                      &&
                      String.IsNullOrEmpty(searchCrit.model) || el.model.StartsWith(searchCrit.model)
                      &&
                      String.IsNullOrEmpty(searchCrit.name) || el.name.StartsWith(searchCrit.name)
                      &&
                      String.IsNullOrEmpty(searchCrit.other) || el.other.StartsWith(searchCrit.other)
                      &&
                      String.IsNullOrEmpty(searchCrit.engine) || el.other.StartsWith(searchCrit.engine)
                      &&
                      (searchCrit.year == null) || (el.year == searchCrit.year)
                      select el;
         return(result);
     }
     catch (System.Data.Entity.Core.EntityException e)
     {
         throw new ServiceException("Database connection error!");
     }
 }
示例#4
0
 public static void UpdateClient(Client client)
 {
     try
     {
         CarWorkshopModelContext dc = new CarWorkshopModelContext();
         var result = (from el in dc.Client
                       where
                       el.id_client == client.id_client
                       select el).SingleOrDefault();
         if (result == null)
         {
             return;
         }
         result.name       = client.name;
         result.first_name = client.first_name;
         result.last_name  = client.last_name;
         result.home       = client.home;
         result.city       = client.city;
         result.flat       = client.flat;
         result.street     = client.street;
         result.PESEL_NIP  = client.PESEL_NIP;
         result.country    = client.country;
         dc.SaveChanges();
     }
     catch (System.Data.Entity.Core.EntityException e)
     {
         throw new ServiceException("Database connection error!");
     }
 }
示例#5
0
 public static void UpdateObject(DataLayer.Object obj)
 {
     try
     {
         CarWorkshopModelContext dc = new CarWorkshopModelContext();
         var result = (from el in dc.Object
                       where
                       el.id_object == obj.id_object
                       select el).SingleOrDefault();
         if (result == null)
         {
             return;
         }
         result.name         = obj.name;
         result.body_type    = obj.body_type;
         result.id_client    = obj.id_client;
         result.manufacturer = obj.manufacturer;
         result.model        = obj.model;
         result.other        = obj.other;
         result.year         = obj.year;
         result.engine       = obj.engine;
         dc.SaveChanges();
     }
     catch (System.Data.Entity.Core.EntityException e)
     {
         throw new ServiceException("Database connection error!");
     }
 }
示例#6
0
 public static IQueryable <Client> GetClients(Client searchCrit)
 {
     try
     {
         CarWorkshopModelContext dc = new CarWorkshopModelContext();
         var result = from el in dc.Client
                      where
                      String.IsNullOrEmpty(searchCrit.name) || el.last_name.StartsWith(searchCrit.name)
                      &&
                      String.IsNullOrEmpty(searchCrit.last_name) || el.last_name.StartsWith(searchCrit.last_name)
                      &&
                      String.IsNullOrEmpty(searchCrit.first_name) || el.first_name.StartsWith(searchCrit.first_name)
                      &&
                      String.IsNullOrEmpty(searchCrit.city) || el.city.StartsWith(searchCrit.city)
                      &&
                      String.IsNullOrEmpty(searchCrit.flat) || el.flat.StartsWith(searchCrit.flat)
                      &&
                      String.IsNullOrEmpty(searchCrit.home) || el.home.StartsWith(searchCrit.home)
                      &&
                      String.IsNullOrEmpty(searchCrit.street) || el.street.StartsWith(searchCrit.street)
                      ||
                      el.id_client == searchCrit.id_client
                      select el;
         return(result);
     }
     catch (System.Data.Entity.Core.EntityException e)
     {
         throw new ServiceException("Database connection error!");
     }
 }
示例#7
0
 public static void UpdatePersonel(Personel personel)
 {
     try
     {
         CarWorkshopModelContext dc = new CarWorkshopModelContext();
         personel.password = Md5Hash(personel.password);
         var res = (from el in dc.Personel
                    where el.id_personel == personel.id_personel
                    select el).SingleOrDefault();
         if (res == null)
         {
             return;
         }
         res.first_name = personel.first_name;
         res.last_name  = personel.last_name;
         if (res.password != personel.password)
         {
             res.password = personel.password;
         }
         res.date_retire = personel.date_retire;
         res.role        = personel.role;
         dc.SaveChanges();
     } catch (System.Data.Entity.Core.EntityException e)
     {
         throw new ServiceException("Database connection error!");
     }
 }
示例#8
0
 public static void NewActivity(Activity activity)
 {
     try
     {
         CarWorkshopModelContext dc = new CarWorkshopModelContext();
         Activity sequneceSearch    = new Activity();
         sequneceSearch.id_request = activity.id_request;
         var sequence = from el in dc.Activity
                        where
                        el.id_request == sequneceSearch.id_request
                        select el;
         if (sequence.ToArray().Length == 0)
         {
             activity.seq_no = 1;
         }
         else
         {
             activity.seq_no = sequence.ToArray().Last().seq_no + 1;
         }
         dc.Activity.Add(activity);
         dc.SaveChanges();
         return;
     } catch (ServiceException e)
     {
         throw e;
     } catch (System.Data.Entity.Core.EntityException e)
     {
         throw new ServiceException("Database connection error!");
     }
     catch (System.Data.Entity.Validation.DbEntityValidationException e)
     {
         var x = e.EntityValidationErrors;
         int a = 0;
     }
 }
示例#9
0
 public static IQueryable <Object_type> GetObjectTypes()
 {
     try
     {
         CarWorkshopModelContext dc = new CarWorkshopModelContext();
         var res = from el in dc.Object_type
                   select el;
         return(res);
     }
     catch (System.Data.Entity.Core.EntityException e)
     {
         throw new ServiceException("Database connection error!");
     }
 }
示例#10
0
 public static void NewRequest(Request request)
 {
     try
     {
         CarWorkshopModelContext dc = new CarWorkshopModelContext();
         dc.Request.Add(request);
         dc.SaveChanges();
         return;
     }
     catch (System.Data.Entity.Core.EntityException e)
     {
         throw new ServiceException("Database connection error!");
     }
 }
示例#11
0
 public static Personel GetPersonelWithPassword(Personel searchCrit)
 {
     try
     {
         searchCrit.password = Md5Hash(searchCrit.password);
         CarWorkshopModelContext dc = new CarWorkshopModelContext();
         var result = from el in dc.Personel
                      where
                      (el.username == searchCrit.username)
                      &&
                      el.password == searchCrit.password
                      select el;
         return(result.SingleOrDefault <Personel>());
     }catch (System.Data.Entity.Core.EntityException e)
     {
         throw new ServiceException("Database connection error!");
     }
 }
示例#12
0
 public static IQueryable <Personel> GetPersonel(Personel searchCrit)
 {
     try
     {
         CarWorkshopModelContext dc = new CarWorkshopModelContext();
         var result = from el in dc.Personel
                      where
                      String.IsNullOrEmpty(searchCrit.last_name) || el.last_name.StartsWith(searchCrit.last_name)
                      &&
                      String.IsNullOrEmpty(searchCrit.first_name) || el.first_name.StartsWith(searchCrit.first_name)
                      &&
                      String.IsNullOrEmpty(searchCrit.username) || el.username.StartsWith(searchCrit.username)
                      select el;
         return(result);
     }
     catch (System.Data.Entity.Core.EntityException e)
     {
         throw new ServiceException("Database connection error!");
     }
 }
示例#13
0
 public static void DeleteClient(Client client)
 {
     try
     {
         CarWorkshopModelContext dc = new CarWorkshopModelContext();
         var res = (from el in dc.Client
                    where el.id_client == client.id_client
                    select el).SingleOrDefault();
         if (res == null)
         {
             return;
         }
         dc.Client.Remove(res);
         dc.SaveChanges();
     }
     catch (System.Data.Entity.Core.EntityException e)
     {
         throw new ServiceException("Database connection error!");
     }
 }
示例#14
0
 public static void NewClient(Client client)
 {
     try
     {
         CarWorkshopModelContext dc = new CarWorkshopModelContext();
         //var res = (from el in dc.Client
         //         where el.username == personel.username
         //       select el).SingleOrDefault();
         //if (res == null)
         //{
         dc.Client.Add(client);
         dc.SaveChanges();
         return;
         //}
         //throw new ServiceException("Username already exists!");
     }
     catch (System.Data.Entity.Core.EntityException e)
     {
         throw new ServiceException("Database connection error!");
     }
 }
示例#15
0
 public static void NewObject(DataLayer.Object obj)
 {
     try
     {
         CarWorkshopModelContext dc = new CarWorkshopModelContext();
         var res = (from el in dc.Object
                    where el.registration_number == obj.registration_number
                    select el).SingleOrDefault();
         if (res == null)
         {
             dc.Object.Add(obj);
             dc.SaveChanges();
             return;
         }
         throw new ServiceException("Object already exists!");
     }
     catch (System.Data.Entity.Core.EntityException e)
     {
         throw new ServiceException("Database connection error!");
     }
 }
示例#16
0
 public static void NewPersonel(Personel personel)
 {
     try
     {
         CarWorkshopModelContext dc = new CarWorkshopModelContext();
         personel.password = Md5Hash(personel.password);
         var res = (from el in dc.Personel
                    where el.username == personel.username
                    select el).SingleOrDefault();
         if (res == null)
         {
             dc.Personel.Add(personel);
             dc.SaveChanges();
             return;
         }
         throw new ServiceException("Username already exists!");
     }
     catch (System.Data.Entity.Core.EntityException e)
     {
         throw new ServiceException("Database connection error!");
     }
 }
示例#17
0
 public static void NewObjectType(Object_type type)
 {
     try
     {
         CarWorkshopModelContext dc = new CarWorkshopModelContext();
         var res = (from el in dc.Object_type
                    where (el.name_type == type.name_type)
                    ||
                    (el.code_type == type.code_type)
                    select el).SingleOrDefault();
         if (res == null)
         {
             dc.Object_type.Add(type);
             dc.SaveChanges();
             return;
         }
         throw new ServiceException("Type already exists!");
     }
     catch (System.Data.Entity.Core.EntityException e)
     {
         throw new ServiceException("Database connection error!");
     }
 }