public IHttpActionResult PutContact(int id, Contact changedContact) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != changedContact.ContactId) { return(BadRequest("Contact not found.")); } db.Entry(changedContact).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ContactExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public object InsertEmployee(Register Reg) { try { EmployeeLogin EL = new EmployeeLogin(); if (EL.Id == 0) { EL.EmployeeName = Reg.EmployeeName; EL.City = Reg.City; EL.Email = Reg.Email; EL.Password = Reg.Password; EL.Department = Reg.Department; DB.EmployeeLogins.Add(EL); DB.SaveChanges(); return(new Response { Status = "Success", Message = "Sucessfully saved to database." }); } } catch (Exception) { throw; } return(new Response { Status = "Error", Message = "Invalid Data" }); }
public Employee AddUpdate(Employee objEmp) { Employee Result = new Employee(); if (objEmp.Id != 0) { try { tempdbEntities objdb = new tempdbEntities(); var empData = objdb.Emps.Where(x => x.Id == objEmp.Id).FirstOrDefault(); if (empData != null) { empData.Name = objEmp.Name; empData.City = objEmp.City; objdb.SaveChanges(); objdb.Dispose(); Result.Status = true; Result.mesage = "success"; } else { Result.Status = false; Result.mesage = "no record found"; } } catch (Exception) { Result.Status = true; Result.mesage = "success"; } } else { try { tempdbEntities objdb = new tempdbEntities(); Emp objemployee = new Emp(); objemployee.Name = objEmp.Name; objemployee.City = objEmp.City; objdb.Emps.Add(objemployee); objdb.SaveChanges(); objdb.Dispose(); Result.Status = true; Result.mesage = "success"; } catch (Exception) { Result.Status = false; Result.mesage = "Falied"; } } return(Result); }
public Employee Delete(int id) { Employee Result = new Employee(); try { if (id > 0) { tempdbEntities objdb = new tempdbEntities(); var empdata = objdb.Emps.Where(x => x.Id == id).FirstOrDefault(); if (empdata != null) { objdb.Emps.Remove(empdata); objdb.SaveChanges(); Result.Status = true; Result.mesage = "Done!"; } else { Result.Status = false; Result.mesage = "Record Not Found!"; } } else { Result.Status = false; Result.mesage = "Invalid Id!"; } } catch (Exception) { Result.Status = false; Result.mesage = "Exception"; } return(Result); }
public object AddorUpdatepatient(Patient pat) { try { if (pat.Id == 0) { patient_details pd = new patient_details(); pd.FirstName = pat.FirstName; pd.LastName = pat.LastName; pd.SSN = pat.SSN; pd.DOB = pat.DOB; pd.Tele_No = pat.Tele_No; pd.Age = pat.Age; pd.Minor_patient = pat.Minor_patient; pd.Address = pat.Address; pd.Country_code = pat.Country_code; pd.Country_Name = pat.Country_Name; pd.Relationship_to_patient = pat.Relationship_to_patient; pd.Guardian_Name = pat.Guardian_Name; DB.patient_details.Add(pd); DB.SaveChanges(); return(new Response { Status = "Success", Message = "Sucessfully saved to database." }); } else { var obj = DB.patient_details.Where(x => x.Id == pat.Id).ToList().FirstOrDefault(); if (obj.Id > 0) { obj.FirstName = pat.FirstName; obj.FirstName = pat.FirstName; obj.LastName = pat.LastName; obj.SSN = pat.SSN; obj.DOB = pat.DOB; obj.Tele_No = pat.Tele_No; obj.Age = pat.Age; obj.Minor_patient = pat.Minor_patient; obj.Address = pat.Address; obj.Country_code = pat.Country_code; obj.Country_Name = pat.Country_Name; obj.Relationship_to_patient = pat.Relationship_to_patient; obj.Guardian_Name = pat.Guardian_Name; DB.SaveChanges(); return(new Response { Status = "Updated", Message = "Sucessfully Updated" }); } } } catch (Exception ex) { Console.Write(ex.Message); } return(new Response { Status = "Error", Message = "Data not inserted." }); }