public Response_String Add_workshop_employee([FromBody] Workshop_Employees New_Employee)
 {
     using (var db = new ITAPPCarWorkshopServiceDBEntities())
     {
         db.Workshop_Employees.Add(New_Employee);
         db.SaveChanges();
         return(new Response_String()
         {
             Response = "Item was added"
         });
     }
 }
Exemple #2
0
        public static HttpResponseMessage CreateNewWorkshopProfile(DataModels.WorkshopProfileModel WorkshopProfileModel, int UserID)
        {
            mutex.WaitOne();

            if (CheckIfWorkshopProfileExistsByNIP(WorkshopProfileModel.WorkshopNIP))
            {
                mutex.ReleaseMutex();
                var response = new HttpResponseMessage(HttpStatusCode.Forbidden);
                response.Content = new StringContent("Workshop of given NIP already exists.");

                return(response);
            }

            var db = new ITAPPCarWorkshopServiceDBEntities();

            ITAPP_CarWorkshopService.Workshop_Profiles WorkshopProfileEntity = WorkshopProfileModel.MakeWorkshopProfileEntityFromWorkshopProfileModel();

            try
            {
                db.Workshop_Profiles.Add(WorkshopProfileEntity);
                db.SaveChanges();

                var NewWorkshopEmployee = new Workshop_Employees()
                {
                    Workshop_empoyee_ID = UserID,
                    Workshop_ID         = WorkshopProfileEntity.Workshop_ID
                };

                db.Workshop_Employees.Add(NewWorkshopEmployee);
                db.SaveChanges();

                mutex.ReleaseMutex();
                var response = new HttpResponseMessage(HttpStatusCode.OK);
                response.Content = new StringContent("Workshop profile was succesfully created");

                return(response);
            }
            catch (Exception e)
            {
                mutex.ReleaseMutex();
                var response = new HttpResponseMessage(HttpStatusCode.InternalServerError);
                response.Content = new StringContent("Something gone wrong while adding the workshop profile to DB");

                return(response);
            }
        }
 public Response_String Modify_workshop_employee([FromBody] Workshop_Employees Modify_Employee)
 {
     using (var db = new ITAPPCarWorkshopServiceDBEntities())
     {
         var Old = db.Workshop_Employees.FirstOrDefault(p => Modify_Employee.Workshop_empoyee_ID == p.Workshop_empoyee_ID);
         if (Old != null)
         {
             var ID = Old.Workshop_empoyee_ID;
             Old = Modify_Employee;
             Old.Workshop_empoyee_ID = ID;
             db.SaveChanges();
             return(new Response_String()
             {
                 Response = "Item was modify"
             });
         }
         return(new Response_String()
         {
             Response = "Item dose not exisit"
         });
     }
 }