S P 4 anos atrás
pai
commit
11199bfebf

+ 59 - 0
WebLab/Controllers/PatientsController.cs

@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.Data.Entity.Infrastructure;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Web.Http;
+using System.Web.Http.Description;
+using WebLab.Entities;
+using WebLab.Models;
+
+namespace WebLab.Controllers
+{
+    public class PatientsController : ApiController
+    {
+        public user1Entities db = new user1Entities();
+        //get
+        [ResponseType(typeof(List<ResponsePatients>))]
+        public IHttpActionResult GetPatients()
+        {
+            return Ok(db.patients.ToList().ConvertAll(t => new ResponsePatients(t)));
+        }
+
+        //post
+        [ResponseType(typeof(patients))]
+        public IHttpActionResult PostPatients(patients p)
+        {
+            if(!ModelState.IsValid)
+            {
+                return BadRequest(ModelState);
+            }
+
+            db.patients.Add(p);
+
+            try
+            {
+                db.SaveChanges();
+            }
+            catch (DbUpdateException)
+            {
+                if (patinetsExist(p.Id))
+                {
+                    return Conflict();
+                }
+                else
+                {
+                    throw;
+                }
+            }
+
+            return CreatedAtRoute("DefaultApi", new { id = p.Id }, p);
+        }
+
+        private bool patinetsExist(int id)
+        {
+            return db.patients.Count(e => e.Id == id) > 0;
+        }
+    }
+}

+ 0 - 1
WebLab/Controllers/usersController.cs

@@ -19,7 +19,6 @@ namespace WebLab.Controllers
 
         // GET: api/users
         [ResponseType(typeof(List<ResponseUsers>))]
-
         public IHttpActionResult Getusers()
         {
             return Ok(db.users.ToList().ConvertAll(t => new ResponseUsers(t)));

+ 35 - 0
WebLab/Models/ResponsePatients.cs

@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using WebLab.Entities;
+
+namespace WebLab.Models
+{
+    public class ResponsePatients
+    {
+        public ResponsePatients(patients p)
+        {
+            Id = p.Id;
+            Name = p.Name;
+            Surname = p.Surname;
+            login = p.login;
+            Password = p.Password;
+        }
+        public int Id { get; set; }
+        public string Name { get; set; }
+        public string Surname { get; set; }
+        public string login { get; set; }
+        public string Password { get; set; }
+        public System.Guid Guid { get; set; }
+        public string Email { get; set; }
+        public string SocialSecNumber { get; set; }
+        public string Ein { get; set; }
+        public string SocialType { get; set; }
+        public string Phone { get; set; }
+        public string PassportS { get; set; }
+        public string PassportN { get; set; }
+        public string BirthDateTimestamp { get; set; }
+        public int IdCompany { get; set; }
+    }
+}

+ 2 - 0
WebLab/WebLab.csproj

@@ -163,6 +163,7 @@
     <Compile Include="Areas\HelpPage\SampleGeneration\TextSample.cs" />
     <Compile Include="Areas\HelpPage\XmlDocumentationProvider.cs" />
     <Compile Include="Controllers\HomeController.cs" />
+    <Compile Include="Controllers\PatientsController.cs" />
     <Compile Include="Controllers\usersController.cs" />
     <Compile Include="Controllers\ValuesController.cs" />
     <Compile Include="Entities\analyzer.cs">
@@ -219,6 +220,7 @@
     <Compile Include="Global.asax.cs">
       <DependentUpon>Global.asax</DependentUpon>
     </Compile>
+    <Compile Include="Models\ResponsePatients.cs" />
     <Compile Include="Models\ResponseUsers.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>