public async Task <IActionResult> Put(string id, [FromBody] CategoryAddCommand command)
        {
            try
            {
                await service.EditAsync
                (
                    id,
                    command
                );

                return(NoContent());
            }
            catch (KeyNotFoundException ex)
            {
                return(NotFound(ex.Message));
            }
            catch (DuplicateWaitObjectException ex)
            {
                return(Conflict(ex.Message));
            }
            catch (HttpRequestException ex)
            {
                return(StatusCode(StatusCodes.Status503ServiceUnavailable, ex.Message));
                //return BadRequest(ex.Message);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Print(ex.ToString());
                return(BadRequest(Error));
            }
        }
Esempio n. 2
0
        public async Task <CategoryDto> AddAsync(CategoryAddCommand command)
        {
            try
            {
                if (await GetCategoryByNameAsync(command.Name) != null)
                {
                    throw new DuplicateWaitObjectException($"{nameof(command.Name)} already exists !");
                }
                var category = new Category(command.Name);
                var result   = await FirebaseClient
                               .Child(Table)
                               .PostAsync(JsonConvert.SerializeObject(category));

                return(GetCategoryDto(result.Key, category));
            }
            catch (Firebase.Database.FirebaseException ex)
            {
                if (ex.InnerException?.InnerException?.GetType() == typeof(SocketException))
                {
                    throw new HttpRequestException("Cannot join the server. Please check your internet connexion.");
                }
                throw ex;
            }
            catch (DuplicateWaitObjectException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 3
0
 public void Add(CategoryAddCommand command)
 {
     Id             = Common.Common.GenerateGuid();
     LanguageId     = command.LanguageId;
     Code           = command.Code;
     CreatedDateUtc = Extensions.GetCurrentDateUtc();
     CreatedUid     = command.CreatedUid;
     UpdatedDateUtc = Extensions.GetCurrentDateUtc();
     UpdatedUid     = command.CreatedUid ?? string.Empty;
     ParentId       = command.ParentId;
     Name           = command.Name;
     Description    = command.Description;
     DisplayOrder   = command.DisplayOrder;
     Version        = command.Version;
     Status         = command.Status;
     AddOrChangeEvent();
 }
Esempio n. 4
0
        public async Task EditAsync(string id, CategoryAddCommand command)
        {
            try
            {
                var oldProduct1 = await GetCategoryAsync(id);

                if (oldProduct1 == null)
                {
                    throw new KeyNotFoundException($"{nameof(Category)} {id} not found");
                }

                var oldProduct2 = await GetCategoryByNameAsync(command.Name);

                if (oldProduct2 != null && oldProduct2.Id != id)
                {
                    throw new DuplicateWaitObjectException($"{nameof(Category)} {command.Name} already exists !");
                }

                await FirebaseClient
                .Child(Table)
                .Child(id)
                .PutAsync(JsonConvert.SerializeObject(new Category(command.Name)));
            }
            catch (Firebase.Database.FirebaseException ex)
            {
                if (ex.InnerException?.InnerException?.GetType() == typeof(SocketException))
                {
                    throw new HttpRequestException("Cannot join the server. Please check your internet connexion.");
                }
                throw ex;
            }
            catch (KeyNotFoundException ex)
            {
                throw ex;
            }
            catch (DuplicateWaitObjectException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public async Task <IActionResult> Post([FromBody] CategoryAddCommand command)
 {
     try
     {
         return(Ok
                (
                    await service.AddAsync(command)
                ));
     }
     catch (DuplicateWaitObjectException ex)
     {
         return(Conflict(ex.Message));
     }
     catch (HttpRequestException ex)
     {
         return(StatusCode(StatusCodes.Status503ServiceUnavailable, ex.Message));
         //return BadRequest(ex.Message);
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.Print(ex.ToString());
         return(BadRequest(Error));
     }
 }
        public async Task <CommandResult> SendCommand(CategoryAddCommand command)
        {
            CommandResult commandResult = await _commandService.SendAndReceiveResult <CommandResult>(command);

            return(commandResult);
        }