public IHttpActionResult EscortAddPicture([FromBody] PictureBindingModel model)
        {
            if (model == null)
            {
                return this.BadRequest("Missing picture data");
            }

            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            var escortId = this.User.Identity.GetUserId();
            var escort = this.EscortServiceData.Escorts
                .FirstOrDefault(e => !e.IsDeleted && e.Id == escortId);

            if (escort == null && escortId != null)
            {
                return this.Content(HttpStatusCode.Unauthorized, new
                {
                    Message = "User " + this.User.Identity.GetUserName() + " is not escort"
                });
            }

            if (this.EscortServiceData.Pictures.Count(p => p.EscortId == escort.Id) > 10)
            {
                return this.BadRequest("An escort allready has 10 pictures.");
            }

            if (this.EscortServiceData.Pictures.Any(p => p.B64 == model.B64))
            {
                return this.Content(HttpStatusCode.Conflict,
                    "This picture already exist");
            }

            var newPicture = new Picture()
            {
                EscortId = escort.Id,
                B64 = model.B64,
                IsProfile = false
            };

            this.EscortServiceData.Pictures.Add(newPicture);
            this.EscortServiceData.SaveChanges();

            return this.Content(HttpStatusCode.OK,
                string.Format("Picture with id: {0}   added successfully to escort: {1} pictures gallery.",
                    newPicture.Id, escort.UserName));
        }
        public async Task<IHttpActionResult> RegisterEscort(RegisterEscortBindingModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            var user = new Escort()
            {
                UserName = model.Username,
                Email = model.Email,
                PhoneNumber = model.PhoneNumber,
                Gender = (Gender)Enum.Parse(typeof(Gender), model.Gender, true),
                Town = model.Town,
                Height = model.Height,
                Weight = model.Weight,
                BreastsType = (BreastsType)Enum.Parse(typeof(BreastsType), model.BreastsType, true),
                Description = model.Description,
                HairColour = model.HairColour,
                IsDeleted = false,
                AddressOfService = model.AddressOfService
            };

            IdentityResult result = await this.UserManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                return this.GetErrorResult(result);
            }
            var newUser = this.EscortServiceData.Users.FirstOrDefault(u => u.UserName == user.UserName);
            if (newUser != null)
            {
                var roleUser = this.UserManager.AddToRole(newUser.Id, "escort");

                if (model.B64 != null)
                {
                    var newPicture = new Picture()
                    {
                        EscortId = newUser.Id,
                        B64 = model.B64,
                        IsProfile = true
                    };

                    this.EscortServiceData.Pictures.Add(newPicture);
                }

                var priceList = this.EscortServiceData.PriceLists
               .FirstOrDefault(p => p.EscortId == newUser.Id);

                if (priceList == null)
                {
                    var newPriceList = new PriceList
                    {
                        EscortId = newUser.Id,
                        ThirtyMinuteRate = null,
                        HourRate = null,
                        ThreeHoursRate = null,
                        SixHoursRate = null,
                        OvernightRate = null,
                        DailyRate = null,
                        WeekendRate = null,
                        WeeklyRate = null
                    };

                    this.EscortServiceData.PriceLists.Add(newPriceList);
                }

                this.EscortServiceData.SaveChanges();
            }

            //Auto login after registration (successful user registration should return access_token)
            //var loginResult = await this.LoginUser(new UserAccountInputModel()
            //{
            //    Username = model.Username,
            //    Password = model.Password
            //});

            //return loginResult;
            return this.Ok();
        }
 public PictureViewModel(Picture picture)
 {
     this.Id = picture.Id;
     this.B64 = picture.B64;
 }