public async Task <ResponseMessageDto> Delete(AddSupplierRequestDto dto)
        {
            try
            {
                await _asyncRepository.DeleteAsync(_mapper.Map <Supplier>(dto));

                return(new ResponseMessageDto()
                {
                    Id = dto.Id,
                    SuccessMessage = ResponseMessages.DeleteSuccessMessage,
                    Success = true,
                    Error = false
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(new ResponseMessageDto()
                {
                    Id = Convert.ToInt16(Enums.FailureId),
                    FailureMessage = ResponseMessages.DeleteFailureMessage,
                    Success = false,
                    Error = true,
                    ExceptionMessage = e.InnerException != null ? e.InnerException.Message : e.Message
                });
            }
        }
Example #2
0
 public async Task <IActionResult> Delete([FromBody] AddSupplierRequestDto dto)
 {
     try
     {
         return(Ok(await _supplierService.Delete(dto)));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
Example #3
0
 public async Task <IActionResult> Put([FromBody] AddSupplierRequestDto dto)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(BadRequest(ModelState));
         }
         return(Ok(await _supplierService.Put(dto)));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
        public async Task <ResponseMessageDto> Put(AddSupplierRequestDto dto)
        {
            try
            {
                if (!await _supplierRepository.IsSupplierNameAvailable(dto.Id, dto.SupplierName))
                {
                    await _asyncRepository.PartialUpdate(dto, m => ///yahan woh values aengi jo ke update karni hongi
                    {
                        m.SupplierName    = dto.SupplierName;
                        m.SupplierAddress = dto.SupplierAddress;
                        m.SupplierContact = dto.SupplierContact;
                    });

                    return(new ResponseMessageDto()
                    {
                        Id = dto.Id,
                        SuccessMessage = ResponseMessages.UpdateSuccessMessage,
                        Success = true,
                        Error = false
                    });
                }

                return(new ResponseMessageDto()
                {
                    FailureMessage = ResponseMessages.SupplierNameNotAvailable,
                    Success = false,
                    Error = true
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(new ResponseMessageDto()
                {
                    Id = Convert.ToInt16(Enums.FailureId),
                    FailureMessage = ResponseMessages.UpdateFailureMessage,
                    Success = false,
                    Error = true,
                    ExceptionMessage = e.InnerException != null ? e.InnerException.Message : e.Message
                });
            }
        }
        public async Task <ResponseMessageDto> Post(AddSupplierRequestDto dto)
        {
            try
            {
                if (!await _supplierRepository.IsSupplierNameAvailable(dto.SupplierName))
                {
                    dto.CreatedOn = DateTime.Now.Date;
                    var supplier = await _asyncRepository.AddAsync(_mapper.Map <Supplier>(dto));

                    return(new ResponseMessageDto()
                    {
                        Id = supplier.Id,
                        SuccessMessage = ResponseMessages.InsertionSuccessMessage,
                        Success = true,
                        Error = false
                    });
                }

                return(new ResponseMessageDto()
                {
                    FailureMessage = ResponseMessages.SupplierNameNotAvailable,
                    Success = false,
                    Error = true
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(new ResponseMessageDto()
                {
                    Id = Convert.ToInt16(Enums.FailureId),
                    FailureMessage = ResponseMessages.InsertionFailureMessage,
                    Success = false,
                    Error = true,
                    ExceptionMessage = e.InnerException != null ? e.InnerException.Message : e.Message
                });
            }
        }