Exemplo n.º 1
0
        public async Task <IHttpActionResult> ChangeType(ChangeBusinessTypeRequest changeBusinessTypeRequestRequest)
        {
            // if the user is null or the user is not authenticated
            if (!IsUserAuthenticated)
            {
                return(Content(HttpStatusCode.Unauthorized, "User must be logged to get businesses."));
            }

            var ownerId = UserId;

            var myBusinesses =
                db.BusinessUsers.Where(
                    businessUser =>
                    businessUser.UserId == ownerId &&
                    businessUser.BusinessId == changeBusinessTypeRequestRequest.BusinessId)
                .Include(businessUser => businessUser.Business).FirstOrDefault();

            var newBusiness = myBusinesses.Business;

            var firstOrDefault =
                db.BusinessTypes.FirstOrDefault(type => type.Name == changeBusinessTypeRequestRequest.Type);

            if (firstOrDefault != null)
            {
                newBusiness.BusinessTypeId =
                    firstOrDefault.Id;
            }

            db.SaveChanges();

            return(Ok());
        }
Exemplo n.º 2
0
        private static void ChangeTypeAction(Guid id)
        {
            Console.WriteLine("Change Type");

            ChangeBusinessTypeRequest request = new ChangeBusinessTypeRequest();

            request.Type = Read <string>("Type");

            request.BusinessId = id;
            try
            {
                bookingBlockClient.BusinessesChangeType(request);
            }
            catch (Exception exception)
            {
                Console.WriteLine("ERROR: " + exception.Message);
            }
        }
Exemplo n.º 3
0
        public void BusinessesChangeType(ChangeBusinessTypeRequest request)
        {
            var q = httpClient.PostAsJsonAsync(AddApiKey("api/businesses/change-type"), request).Result;

            q.EnsureSuccessStatusCode();
        }