コード例 #1
0
        public async Task AddOrUpdateDoctorAsync(DoctorSettings user, string id)
        {
            var cloudTable = await _tableStorage.GetTableReference(_doctorTable);

            var userEntity = new DoctorSettingsEntity()
            {
                PartitionKey = id,
                RowKey       = user.Name + '.' + user.Lastname,
                Model        = user
            };
            var op = TableOperation.InsertOrReplace(userEntity);
            await cloudTable.ExecuteAsync(op);
        }
コード例 #2
0
        public async Task <IActionResult> UpdateUser(string id, DoctorSettings model)
        {
            try
            {
                await _userRepository.AddOrUpdateDoctorAsync(model, id);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(Ok(new ApiControllerDataResult <object>
                {
                    Errors = new List <JsonApiErrorModel>()
                    {
                        new JsonApiErrorModel
                        {
                            Title = "Add or Update",
                            Detail = ex.Message
                        }
                    }
                }));
            }
        }
コード例 #3
0
        public async Task <IActionResult> Register(RegistrationModel registration)
        {
            if (!ModelState.IsValid)
            {
                return(Ok(new ApiControllerDataResult <object>
                {
                    Errors = new List <JsonApiErrorModel>()
                    {
                        new JsonApiErrorModel
                        {
                            Title = "Model isn't valid exist",
                            Detail = "Bad values"
                        }
                    }
                }));
            }

            bool userExist = await _userRepository.CheckIfUserExist(registration.Login.ToUpper());

            if (userExist)
            {
                return(Ok(new ApiControllerDataResult <object>
                {
                    Errors = new List <JsonApiErrorModel>()
                    {
                        new JsonApiErrorModel
                        {
                            Title = "User exist",
                            Detail = "This login exist"
                        }
                    }
                }
                          ));
            }

            var user = new UserEntity {
                UserName = registration.Login, Role = registration.UserRole
            };
            var result = await _userManager.CreateAsync(user, registration.Password);

            if (!result.Errors.Any())
            {
                await _signInManager.SignInAsync(user, false);

                if (registration.UserRole.ToLower() == "user")
                {
                    var model = new PersonalDataSettings
                    {
                        Name            = registration.Name,
                        Lastname        = registration.Lastname,
                        City            = registration.City,
                        Adress          = registration.Adress,
                        PostalCode      = registration.PostalCode,
                        TelephoneNumber = registration.TelephoneNumber
                    };
                    await _userRepository.AddOrUpdateUserAsync(model, user.Id);
                }
                else
                {
                    var model = new DoctorSettings
                    {
                        Name            = registration.Name,
                        Lastname        = registration.Lastname,
                        City            = registration.City,
                        Adress          = registration.Adress,
                        PostalCode      = registration.PostalCode,
                        TelephoneNumber = registration.TelephoneNumber,
                        LicenceNumber   = "0000",
                        Specialisation  = "ogolna"
                    };
                    await _userRepository.AddOrUpdateDoctorAsync(model, user.Id);
                }
                return(Ok(new ApiControllerDataResult <UserEntity> {
                    Data = user
                }));
            }
            else
            {
                var errors = new List <JsonApiErrorModel>();
                foreach (var error in result.Errors)
                {
                    errors.Add(new JsonApiErrorModel {
                        Title = "Registation error", Detail = error.Description
                    });
                }
                return(Ok(new ApiControllerDataResult <object> {
                    Errors = errors
                }));
            }
        }
コード例 #4
0
        public override void ReadEntity(IDictionary <string, EntityProperty> properties, OperationContext context)
        {
            string birthDate       = "";
            string telephoneNumber = "";
            string adress          = "";
            string postalCode      = "";
            string city            = "";
            string name            = "";
            string lastname        = "";
            string licenceNumber   = "";
            string specialisation  = "";

            foreach (var prop in properties)
            {
                switch (prop.Key.ToLower())
                {
                case "name":
                    name = prop.Value.StringValue;
                    break;

                case "lastname":
                    lastname = prop.Value.StringValue;
                    break;

                case "city":
                    city = prop.Value.StringValue;
                    break;

                case "adress":
                    adress = prop.Value.StringValue;
                    break;

                case "postalcode":
                    postalCode = prop.Value.StringValue;
                    break;

                case "telephonenumber":
                    telephoneNumber = prop.Value.StringValue;
                    break;

                case "agedate":
                    birthDate = prop.Value.StringValue;
                    break;

                case "licencenumber":
                    licenceNumber = prop.Value.StringValue;
                    break;

                case "specialisation":
                    specialisation = prop.Value.StringValue;
                    break;
                }
            }

            Model = new DoctorSettings
            {
                Adress          = adress,
                AgeDate         = birthDate,
                City            = city,
                Name            = name,
                Lastname        = lastname,
                PostalCode      = postalCode,
                TelephoneNumber = telephoneNumber,
                LicenceNumber   = licenceNumber,
                Specialisation  = specialisation
            };
        }