Beispiel #1
0
        public IHttpActionResult PutExamination(int id, Examination examination)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #2
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 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));
        }
Beispiel #4
0
        public IHttpActionResult PutUser(int id, UserDto user)
        {
            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 tmp = db.Users.Find(id);

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

            tmp.Name        = user.Name;
            tmp.Surname     = user.Surname;
            tmp.Phone       = user.Phone;
            tmp.DateOfBirth = user.DateOfBirth;
            tmp.Address     = user.Address;
            tmp.Gender      = user.Gender;


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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                throw;
            }
            catch (DbEntityValidationException ex)
            {
                return(BadRequest(Messages.BadDataInFields));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        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));
        }
        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));
        }
Beispiel #7
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 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));
            }
        }
Beispiel #9
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));
        }
Beispiel #10
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());
        }