Пример #1
0
        public HttpResponseMessage Create(string email, string password, string firstName, string lastName, string middleName, string phoneNumber, byte[] photo, bool status = true)
        {
            var repository = new UserRepository();

            var user = repository.GetByEmail(email);

            if (user == null || user.Id == 0)
            {
                var entity = new User();
                entity.Email       = email;
                entity.Password    = password;
                entity.FirstName   = firstName;
                entity.LastName    = lastName;
                entity.MiddleName  = middleName;
                entity.Photo       = photo;
                entity.PhoneNumber = phoneNumber;
                entity.Status      = status;

                entity = repository.AddEdit(entity);
                var json = JsonConvert.SerializeObject(entity);
                return(new HttpResponseMessage {
                    Content = new StringContent(json, Encoding.UTF8, "application/json")
                });
            }
            else
            {
                var json = new { status = true, message = "Пользователь с введенным логином уже существует." };
                return(new HttpResponseMessage {
                    Content = new StringContent(JsonConvert.SerializeObject(json), Encoding.UTF8, "application/json")
                });
            }
        }
Пример #2
0
        public HttpResponseMessage LogIn(string login, string password)
        {
            var repository = new UserRepository();

            var json   = CreatorsHubLogin(login, password);
            var result = JsonConvert.DeserializeObject <dynamic>(json);

            if (result.result != null && result.result == 1)
            {
                var entity = repository.Login(login);
                if (entity == null || entity.Id == 0)
                {
                    entity = repository.AddEdit(new User()
                    {
                        UserName   = login,
                        EmployeeId = Convert.ToInt32(result.uid),
                        FirstName  = result.first_name,
                        LastName   = result.last_name,
                        MiddleName = result.middle_name,
                        Status     = true
                    });
                }

                json = JsonConvert.SerializeObject(entity);
            }

            return(new HttpResponseMessage {
                Content = new StringContent(json, Encoding.UTF8, "application/json")
            });
        }
Пример #3
0
        public HttpResponseMessage ChangePhone(string login, string password, string phone)
        {
            var repository = new UserRepository();
            var entity     = repository.Login(login, password);

            if (entity != null && entity.Id > 0)
            {
                entity.PhoneNumber = phone;
                entity             = repository.AddEdit(entity);
            }
            var json = JsonConvert.SerializeObject(entity);

            return(new HttpResponseMessage {
                Content = new StringContent(json, Encoding.UTF8, "application/json")
            });
        }
Пример #4
0
        public HttpResponseMessage ChangePicture(int userId, byte[] photo)
        {
            var repository = new UserRepository();
            var entity     = repository.Get(userId);

            if (entity != null && entity.Id > 0)
            {
                entity.Photo = photo;
                entity       = repository.AddEdit(entity);
            }
            var json = JsonConvert.SerializeObject(entity);

            return(new HttpResponseMessage {
                Content = new StringContent(json, Encoding.UTF8, "application/json")
            });
        }
Пример #5
0
        public HttpResponseMessage Update(int userId, string email = null, string firstName = null, string lastName = null, string middleName = null, string phoneNumber = null)
        {
            var repository = new UserRepository();

            var entity = repository.Get(userId);

            if (entity != null && entity.Id > 0)
            {
                if (!string.IsNullOrEmpty(email))
                {
                    entity.Email = email;
                }
                if (!string.IsNullOrEmpty(firstName))
                {
                    entity.FirstName = firstName;
                }
                if (!string.IsNullOrEmpty(lastName))
                {
                    entity.LastName = lastName;
                }
                if (!string.IsNullOrEmpty(middleName))
                {
                    entity.MiddleName = middleName;
                }
                if (!string.IsNullOrEmpty(phoneNumber))
                {
                    entity.PhoneNumber = phoneNumber;
                }

                entity = repository.AddEdit(entity);
            }
            var json = JsonConvert.SerializeObject(entity);

            return(new HttpResponseMessage {
                Content = new StringContent(json, Encoding.UTF8, "application/json")
            });
        }