public async Task <IActionResult> UpdateDiseaseRecordsForm([FromBody] DiseaseRecordsFormDTO form)
        {
            if (string.IsNullOrEmpty(CurrentUserName))
            {
                return(Unauthorized());
            }

            await _profileService.UpdateDiseaseRecordsFormAsync(CurrentUserName, form);

            return(Ok());
        }
Example #2
0
        public async Task UpdateDiseaseRecordsFormAsync(string mobile, DiseaseRecordsFormDTO form)
        {
            var person = await _dbContext.Persons.FirstOrDefaultAsync(x => x.Mobile == mobile);

            if (person == null)
            {
                throw new AwroNoreException(NewResource.UserNotFound);
            }

            var currentForm = await _dbContext.DiseaseRecordsForms.FirstOrDefaultAsync(X => X.PersonId == person.Id);

            if (currentForm == null)
            {
                currentForm = new DiseaseRecordsForm
                {
                    PersonId                    = person.Id,
                    Age                         = form.Age,
                    DoYouSmoke                  = form.DoYouSmoke,
                    DrugsYouUsed                = form.DrugsYouUsed,
                    HadSurgery                  = form.HadSurgery,
                    HasLongTermDisease          = form.HasLongTermDisease,
                    LongTermDiseasesDescription = form.LongTermDiseasesDescription,
                    MedicalAllergies            = form.MedicalAllergies,
                    SurgeriesDescription        = form.SurgeriesDescription
                };

                await _dbContext.DiseaseRecordsForms.AddAsync(currentForm);

                await _dbContext.SaveChangesAsync();
            }
            else
            {
                currentForm.Age                         = form.Age;
                currentForm.DoYouSmoke                  = form.DoYouSmoke;
                currentForm.DrugsYouUsed                = form.DrugsYouUsed;
                currentForm.HadSurgery                  = form.HadSurgery;
                currentForm.HasLongTermDisease          = form.HasLongTermDisease;
                currentForm.LongTermDiseasesDescription = form.LongTermDiseasesDescription;
                currentForm.MedicalAllergies            = form.MedicalAllergies;
                currentForm.SurgeriesDescription        = form.SurgeriesDescription;

                _dbContext.DiseaseRecordsForms.Attach(currentForm);

                _dbContext.Entry(currentForm).State = EntityState.Modified;

                await _dbContext.SaveChangesAsync();
            }
        }