Exemple #1
0
        public IHttpActionResult PatchActiveState(int id, JsonPatchDocument <User> patchData)
        {
            var currentUser = db.Users.FirstOrDefault(x => x.Email == User.Identity.Name);

            if (!User.IsInRole(Roles.Administrator) && currentUser.UserId != id)
            {
                return(Content(HttpStatusCode.Forbidden, Messages.AccsesDenied));
            }

            var objectToUpdate = db.Users.Find(id);

            patchData.ApplyTo(objectToUpdate);

            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                var s = "";
                foreach (var eve in e.EntityValidationErrors)
                {
                    s += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                       eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        s += string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                           ve.PropertyName, ve.ErrorMessage);
                    }
                }

                return(BadRequest(s));
            }
            return(Ok());
        }
        public IHttpActionResult PutFeedback(int id, Feedback feedback)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != feedback.FeedbackId)
            {
                return(BadRequest());
            }

            db.Entry(feedback).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FeedbackExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #3
0
        public IHttpActionResult PutVaccination(int id, Vaccination vaccination)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != vaccination.ProcedureId)
            {
                return(BadRequest());
            }

            db.Entry(vaccination).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VaccinationExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #4
0
        public IHttpActionResult PutDoctor(int id, Doctor doctor)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != doctor.UserId)
            {
                return(BadRequest());
            }

            db.Entry(doctor).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DoctorExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult UpdateAndConfirmAppointment(int id, Appointment appointment)
        {
            var currentUser = db.Users.FirstOrDefault(x => x.Email == this.User.Identity.Name);

            if (appointment.DoctorId != currentUser.UserId && Tools.AnyRole(this.User, Roles.DoctorRoles))
            {
                return(Content(HttpStatusCode.Forbidden, Messages.AccsesDenied));
            }

            appointment.AppointmentId = id;

            db.Entry(appointment).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AppointmentExists(id))
                {
                    return(NotFound());
                }
                throw;
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #6
0
        public IHttpActionResult PutWarningLabel(int id, WarningLabel warningLabel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != warningLabel.WarningLabelId)
            {
                return(BadRequest());
            }



            db.Entry(warningLabel).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WarningLabelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PatchMedicationPrice(int id, JsonPatchDocument <Medication> patchData)
        {
            var objectToUpdate = db.Medications.Find(id);

            patchData.ApplyTo(objectToUpdate);

            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                string s = "";
                foreach (var eve in e.EntityValidationErrors)
                {
                    s += String.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                       eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        s += String.Format("- Property: \"{0}\", Error: \"{1}\"",
                                           ve.PropertyName, ve.ErrorMessage);
                    }
                }

                return(BadRequest(s));
            }
            return(Ok());
        }
        public IHttpActionResult PutTreatment(int id, Treatment treatment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var tre = db.Treatments.Find(id);

            if (tre.Result == null && treatment.Result != null)
            {
                tre.Result          = treatment.Result;
                db.Entry(tre).State = EntityState.Modified;
            }
            else
            {
                tre.Medications = treatment.Medications;

                var ids = (from n in tre.Medications
                           select n.MedicationId).ToArray <int>();
                List <Medication> meds = (from m in db.Medications.Include(x => x.Treatments)
                                          from id1 in ids
                                          where m.MedicationId == id1
                                          select m
                                          ).ToList();
                tre.Medications = meds;
                foreach (Medication med in meds)
                {
                    med.Treatments.Add(tre);
                }
                db.Entry(tre).State = EntityState.Modified;
                foreach (Medication med in meds)
                {
                    db.Entry(med).State = EntityState.Modified;
                }
            }
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TreatmentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> UploadFile(int id)
        {
            HttpRequestMessage request = this.Request;

            if (!request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }
            try
            {
                var currentUser = db.Users.FirstOrDefault(x => x.Email == this.User.Identity.Name);

                if (currentUser == null)
                {
                    return(NotFound());
                }

                if (!this.User.IsInRole(Roles.Administrator) && id != currentUser.UserId)
                {
                    return(Content(HttpStatusCode.Forbidden, Messages.AccsesDenied));
                }

                var streamProvider = new FilenameMultipartFormDataStreamProvider(ServerUploadFolder);
                await Request.Content.ReadAsMultipartAsync(streamProvider);


                var fileName = Path.GetFileName(streamProvider.FileData.Select(entry => entry.LocalFileName).First());

                var user = db.Users.Find(id);

                if (user == null)
                {
                    return(NotFound());
                }

                user.URLImage = "img/" + fileName;

                db.Entry(user).State = System.Data.Entity.EntityState.Modified;

                db.SaveChanges();
                return(Ok(Constants.ThisServer + "img/" + fileName));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemple #10
0
 public IHttpActionResult PostDepartment(Department department)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         db.Departments.Add(department);
         db.SaveChanges();
     }
     catch (Exception)
     {
         return(InternalServerError());
     }
     return(Ok(department.DepartmentId));
 }
Exemple #11
0
        public IHttpActionResult PutEmployee(int id, EmployeeDto employeeDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != employeeDto.UserId)
            {
                return(BadRequest());
            }

            var emp = db.Employees.Find(employeeDto.UserId);

            var elm = db.Users.FirstOrDefault(x => x.Email == employeeDto.Email);

            if (elm != null && elm.UserId != id)
            {
                return(BadRequest("Email is allready exists"));
            }

            employeeDto.UpateEmployee(emp);

            db.Entry(emp).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(InternalServerError());
            }
            catch (Exception)
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Exemple #12
0
        public static void  AddDoctors()
        {
            List <string> address     = ReadFromFile(addressFile);
            List <string> names       = ReadFromFile(smallNameFile);
            List <string> emails      = ReadFromFile(emailFaile);
            List <string> passwords   = ReadFromFile(passwordFile);
            List <string> degrees     = ReadFromFile(degreeFile);
            List <string> phones      = ReadFromFile(phoneFile);
            List <string> universitys = ReadFromFile(universityFile);
            List <string> birthDate   = ReadFromFile(dateFile);
            List <string> employDate  = ReadFromFile(employmentDate);


            AlphaMedicContext db = new AlphaMedicContext();

            var deps = db.Departments.Select(x => x.DepartmentId).ToList();



            Random        rnd = new Random();
            List <Doctor> doc = new List <Doctor>();

            for (int i = 0; i < 30; i++)
            {
                doc.Add(new Doctor());

                doc.Last().Name                       = names[i].Split(' ')[0];
                doc.Last().Surname                    = names[i].Split(' ')[1];
                doc.Last().Phone                      = phones[i];
                doc.Last().Gender                     = GenderType.Male;
                doc.Last().DateOfBirth                = Convert.ToDateTime(birthDate[i]);
                doc.Last().Address                    = address[i];
                doc.Last().Email                      = emails[i];
                doc.Last().Password                   = passwords[i];
                doc.Last().Active                     = true;
                doc.Last().EmploymentDate             = Convert.ToDateTime(employDate[i]);
                doc.Last().EmploymentRecordBookNumber = rnd.Next(111111, 999999).ToString();
                doc.Last().DismissalDate              = null;
                doc.Last().EmployeeType               = EmployeeType.Doctor;
                doc.Last().Degree                     = degrees[rnd.Next(0, 10)];
                doc.Last().Education                  = universitys[rnd.Next(0, 34)];
                doc.Last().Schedule                   = null;
                doc.Last().DepartmentId               = deps[rnd.Next(0, deps.Count())];

                doc.Last().DoctorType = 0;
                db.Doctors.Add(doc.Last());
            }

            db.SaveChanges();
        }
Exemple #13
0
        public static void AddChedules()
        {
            AlphaMedicContext db  = new AlphaMedicContext();
            Random            rnd = new Random();

            for (int i = 0; i < 200; i++)
            {
                Schedule sch   = new Schedule();
                var      start = rnd.Next(0, 16);
                sch.StartWorkingTime  = TimeSpan.FromHours(start);
                sch.FinishWorkingTime = TimeSpan.FromHours(start + 8);
                db.Schedules.Add(sch);
            }
            db.SaveChanges();
        }
Exemple #14
0
        public IHttpActionResult PutUser2(int id, object state)
        {
            var user = db.Users.Find(id);

            if (user == null)
            {
                return(NotFound());
            }


            if (user.Active != true)
            {
                user.Active = true;
            }

            db.Entry(user).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
                return(Ok());
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PatientExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }