예제 #1
0
        public async Task <IActionResult> GetAccount(long id)
        {
            string method = nameof(GetAccount);

            LogHandler.LogMethod(LogHandler.EventType.Call, Logger, method, id);
            SingleResponse <object> response = new SingleResponse <object>();

            try
            {
                var existingEntity = await DbContext.GetAccount(new Account { id = id });

                if (existingEntity == null)
                {
                    response.ErrorCode = (int)ErrorHandler.ErrorCode.NoContent;
                    return(response.ToHttpResponse(Logger, method));
                }
                response.Model     = existingEntity;
                response.ErrorCode = (int)ErrorHandler.ErrorCode.OK;
            }
            catch (Exception ex)
            {
                LogHandler.LogError(Logger, response, method, ex);
            }
            return(response.ToHttpResponse(Logger, method));
        }
        public async Task <IActionResult> AddDeposit([FromBody] AddDepositRequest request)
        {
            string method = nameof(AddDeposit);

            LogHandler.LogMethod(LogHandler.EventType.Call, Logger, method, request);
            SingleResponse <object> response = new SingleResponse <object>();

            try
            {
                if (!request.CheckValidation(response))
                {
                    return(response.ToHttpResponse(Logger, method));
                }

                var deposit   = request.ToEntity(false);
                var purchases = request.ToPurchaseEntity();
                if (purchases.Sum(x => x.amount) != deposit.amount)
                {
                    response.ErrorCode    = (int)ErrorHandler.ErrorCode.BadRequest;
                    response.ErrorMessage = Constants.MessageText.PurcheseAmountSumError;
                    return(response.ToHttpResponse(Logger, method));
                }
                deposit.purchases = purchases;
                DbContext.Add(deposit);
                int save = await DbContext.SaveChangesAsync();

                if (save == 0)
                {
                    response.ErrorCode = (int)ErrorHandler.ErrorCode.DbSaveNotDone;
                    return(response.ToHttpResponse(Logger, method));
                }
                var entity_list = new List <Deposit> {
                    deposit
                }
                .Select(x => new
                {
                    x.account_id,
                    x.account_name,
                    x.cancel_cost,
                    x.count,
                    x.date,
                    x.fund_name,
                    x.id,
                    x.issue_cost,
                    x.purchases_count,
                    x.status,
                    x.unit_cost_id,
                    x.amount,
                    x.create_date,
                    x.creator_id
                }).First();
                response.Model     = entity_list;
                response.ErrorCode = (int)ErrorHandler.ErrorCode.OK;
            }
            catch (Exception ex)
            {
                LogHandler.LogError(Logger, response, method, ex);
            }
            return(response.ToHttpResponse(Logger, method));
        }
        public async Task <IActionResult> DeleteDeposit(long id)
        {
            string method = nameof(DeleteDeposit);

            LogHandler.LogMethod(LogHandler.EventType.Call, Logger, method, id);
            SingleResponse <object> response = new SingleResponse <object>();

            try
            {
                var existingEntity = await DbContext.GetDeposit(new Deposit { id = id });

                if (existingEntity == null)
                {
                    response.ErrorCode = (int)ErrorHandler.ErrorCode.NoContent;
                    return(response.ToHttpResponse(Logger, method));
                }

                DbContext.Remove(existingEntity);
                int save = await DbContext.SaveChangesAsync();

                if (save == 0)
                {
                    response.ErrorCode = (int)ErrorHandler.ErrorCode.DbSaveNotDone;
                    return(response.ToHttpResponse(Logger, method));
                }
                response.Model     = true;
                response.ErrorCode = (int)ErrorHandler.ErrorCode.OK;
            }
            catch (Exception ex)
            {
                LogHandler.LogError(Logger, response, method, ex);
            }
            return(response.ToHttpResponse(Logger, method));
        }
        public async Task <IActionResult> GetServiceCartcount()
        {
            int?userId    = 0;
            var userStrId = this.User.FindFirstValue(ClaimTypes.Name);

            if (!string.IsNullOrWhiteSpace(userStrId))
            {
                userId = Convert.ToInt32(userStrId);
            }

            var response = new SingleResponse <CartCountResponseViewModel>();

            try
            {
                var dataResult = (await _unit.ICart.CartCountAndPrice(userId: userId.Value));
                response.Data    = dataResult.HasSuccess ? dataResult.UserObject : null;
                response.Message = "Cart added";
                response.Status  = true;
                return(response.ToHttpResponse());
            }
            catch (Exception ex)
            {
                response.Status  = false;
                response.Message = "There was an internal error, please contact to technical support.";
                ErrorTrace.Logger(LogArea.ApplicationTier, ex);
            }
            return(response.ToHttpResponse());
        }
        public async Task <IActionResult> GetOrderDetailByOrderId([FromQuery] int orderId)
        {
            int?   userId    = 0;
            string strStatus = string.Empty;
            var    userStrId = this.User.FindFirstValue(ClaimTypes.Name);

            if (!string.IsNullOrWhiteSpace(userStrId))
            {
                userId = Convert.ToInt32(userStrId);
            }


            var ownResponse = new SingleResponse <DeliveryBoyOrderDetailResponseModel>();
            var dataResult  = await _unit.IOrder.GetDeliveryBoyOrderByOrderId(userId.Value, orderId);

            if (dataResult.HasSuccess)
            {
                ownResponse.Message = "Success";
                ownResponse.Status  = true;
                ownResponse.Data    = dataResult.UserObject;
                return(ownResponse.ToHttpResponse());
            }
            else
            {
                ownResponse.Message = "No data found";
                ownResponse.Status  = true;
                ownResponse.Data    = dataResult.UserObject;
                return(ownResponse.ToHttpResponse());
            }
        }
예제 #6
0
        [ProducesResponseType(500)] //If there was an internal server error
        public async Task <IActionResult> GetUserDetailsAndRolesAsync(string userName)
        {
            var response = new SingleResponse <dynamic>();

            if (userName == null || userName == string.Empty)
            {
                response.DidValidationError = true;
                response.ErrorMessage       = "User Name is incorrect";
                response.DidValidationError = true;
                return(response.ToHttpResponse());
            }

            List <UserRoleBindingModel> userRolesBindingModel = new List <UserRoleBindingModel>();
            UserBindingModel            userBindingModel      = new UserBindingModel();
            User            user  = new User();
            List <UserRole> roles = new List <UserRole>();

            user = await this._authenticationService.GetUserDetailsByUserNameAsync(userName);

            if (user == null)
            {
                response.DidValidationError = true;
                response.ErrorMessage       = "User Name - " + userName + "not found";
                return(response.ToHttpResponse());
            }

            List <UserRole> userRoles = await this._userManagementService.GetUserRolesAsync(user);

            userBindingModel      = this._mapper.Map <UserBindingModel>(user);
            userRolesBindingModel = this._mapper.Map <List <UserRoleBindingModel> >(userRoles);

            response.Model = (userDetails : userBindingModel, userRoles : userRolesBindingModel);

            return(response.ToHttpResponse());
        }
예제 #7
0
        public async Task <IActionResult> Handle(LOIDocumentUploadCommand request, CancellationToken cancellationToken)
        {
            var _response = new SingleResponse <UplodLoiDocFileResponse>();

            if (request.LoiDocFile != null)
            {
                string strDirectory = "\\LOIDocumnetUpload" + "\\" + Regex.Replace(request.FranchiseeId.ToString(), @"\s+", "");

                Tbluserdoument documentdata = new Tbluserdoument();
                var            fileResult   = WriteFile(request.LoiDocFile, strDirectory, "").Result;

                if (request.DocumentId > 0)
                {
                    documentdata.Id = request.DocumentId;
                }

                if (fileResult.HasSuccess)
                {
                    documentdata.DocImagePath = fileResult.UserObject.ImagePath;
                }

                documentdata.UserId         = request.FranchiseeId;
                documentdata.InsertedBy     = request.CurrentUserId;
                documentdata.DocumentTypeId = 6;
                documentdata.UserTypeId     = request.CurrentUserTypeId;
                documentdata.Remark         = request.LoiDocFile.FileName;
                documentdata.InsertDate     = DateTime.Now;
                documentdata.LastUpdateDate = DateTime.Now;
                documentdata.Status         = 1;
                try
                {
                    var result = await _account.FranchiseeLoiUpload(documentdata);

                    if (result.HasSuccess)
                    {
                        _response.Status  = true;
                        _response.Message = result.ResultCode.MessageText;
                        _response.Data    = result.UserObject;
                        return(_response.ToHttpResponse());
                    }
                    else
                    {
                        _response.Status  = false;
                        _response.Message = result.ResultCode.MessageText;
                        return(_response.ToHttpResponse());
                    }
                }
                catch (Exception ex)
                {
                    ErrorTrace.Logger(LogArea.ProviderLayer, ex);
                    _response.Status  = false;
                    _response.Message = "Exception";
                }
                return(_response.ToHttpResponse());
            }
            _response.Status  = false;
            _response.Message = "Please upload file";
            return(_response.ToHttpResponse());
        }
예제 #8
0
        public async Task <IActionResult> EditUnitCost([FromBody] AddUnitCostRequest request)
        {
            string method = nameof(EditUnitCost);

            LogHandler.LogMethod(LogHandler.EventType.Call, Logger, method, request);
            SingleResponse <object> response = new SingleResponse <object>();

            try
            {
                if (!request.CheckValidation(response))
                {
                    return(response.ToHttpResponse(Logger, method));
                }

                var entity = request.ToEntity();
                entity.id = request.id;

                var existingEntity = await DbContext.GetUnitcost(entity);

                if (existingEntity == null)
                {
                    response.ErrorCode = (int)ErrorHandler.ErrorCode.NoContent;
                    return(response.ToHttpResponse(Logger, method));
                }

                existingEntity.cancel_cost = entity.cancel_cost;
                existingEntity.date        = entity.date;
                existingEntity.fund_id     = entity.fund_id;
                existingEntity.issue_cost  = entity.issue_cost;

                int save = await DbContext.SaveChangesAsync();

                if (save == 0)
                {
                    response.ErrorCode = (int)ErrorHandler.ErrorCode.DbSaveNotDone;
                    return(response.ToHttpResponse(Logger, method));
                }
                var entity_list = new List <UnitCost> {
                    entity
                }
                .Select(x => new
                {
                    x.id,
                    x.create_date,
                    x.creator_id,
                    x.date,
                    x.cancel_cost,
                    x.issue_cost,
                    x.fund_id
                }).First();
                response.Model     = entity_list;
                response.ErrorCode = (int)ErrorHandler.ErrorCode.OK;
            }
            catch (Exception ex)
            {
                LogHandler.LogError(Logger, response, method, ex);
            }
            return(response.ToHttpResponse(Logger, method));
        }
예제 #9
0
        public async Task <IActionResult> EditSetting([FromBody] AddSettingRequest request)
        {
            string method = nameof(EditSetting);

            LogHandler.LogMethod(LogHandler.EventType.Call, Logger, method, request);
            SingleResponse <object> response = new SingleResponse <object>();

            try
            {
                if (!request.CheckValidation(response))
                {
                    return(response.ToHttpResponse(Logger, method));
                }

                var entity = request.ToEntity(true);

                var existingEntity = await DbContext.GetSetting(entity);

                if (existingEntity == null)
                {
                    response.ErrorCode = (int)ErrorHandler.ErrorCode.NoContent;
                    return(response.ToHttpResponse(Logger, method));
                }

                existingEntity.type   = entity.type;
                existingEntity.key    = entity.key;
                existingEntity.value  = entity.value;
                existingEntity.status = entity.status;

                int save = await DbContext.SaveChangesAsync();

                if (save == 0)
                {
                    response.ErrorCode = (int)ErrorHandler.ErrorCode.DbSaveNotDone;
                    return(response.ToHttpResponse(Logger, method));
                }
                var entity_list = new List <Setting> {
                    entity
                }
                .Select(x => new
                {
                    x.id,
                    x.create_date,
                    x.creator_id,
                    x.type,
                    x.key,
                    x.value,
                    x.status
                }).First();
                response.Model     = entity_list;
                response.ErrorCode = (int)ErrorHandler.ErrorCode.OK;
            }
            catch (Exception ex)
            {
                LogHandler.LogError(Logger, response, method, ex);
            }
            return(response.ToHttpResponse(Logger, method));
        }
예제 #10
0
        public async Task <IActionResult> AddAccount([FromBody] AddAccountRequest request)
        {
            string method = nameof(AddAccount);

            LogHandler.LogMethod(LogHandler.EventType.Call, Logger, method, request);
            SingleResponse <object> response = new SingleResponse <object>();

            try
            {
                if (!request.CheckValidation(response))
                {
                    return(response.ToHttpResponse(Logger, method));
                }

                var account = request.ToEntity();

                var existingEntity = await DbContext.GetAccount(account);

                if (existingEntity != null)
                {
                    response.ErrorCode = (int)ErrorHandler.ErrorCode.AddRepeatedEntity;
                    return(response.ToHttpResponse(Logger, method));
                }

                DbContext.Add(account);
                int save = await DbContext.SaveChangesAsync();

                if (save == 0)
                {
                    response.ErrorCode = (int)ErrorHandler.ErrorCode.DbSaveNotDone;
                    return(response.ToHttpResponse(Logger, method));
                }
                var entity_list = new List <Account> {
                    account
                }
                .Select(x => new
                {
                    x.id,
                    x.create_date,
                    x.creator_id,
                    x.accounter_id,
                    x.accounter_name,
                    x.fund_name,
                    x.fund_id,
                    x.name,
                    x.status,
                    x.no
                }).First();
                response.Model     = entity_list;
                response.ErrorCode = (int)ErrorHandler.ErrorCode.OK;
            }
            catch (Exception ex)
            {
                LogHandler.LogError(Logger, response, method, ex);
            }
            return(response.ToHttpResponse(Logger, method));
        }
예제 #11
0
        public async Task <IActionResult> AddSetting([FromBody] AddSettingRequest request)
        {
            string method = nameof(AddSetting);

            LogHandler.LogMethod(LogHandler.EventType.Call, Logger, method, request);
            SingleResponse <object> response = new SingleResponse <object>();

            try
            {
                if (!request.CheckValidation(response))
                {
                    return(response.ToHttpResponse(Logger, method));
                }

                var user = request.ToEntity();

                if (user.type == SettingType.AnnualProfit)
                {
                    var existingEntity = DbContext.GetSettings(null, user.type);
                    if (existingEntity?.Count() > 0)
                    {
                        response.ErrorCode = (int)ErrorHandler.ErrorCode.AddRepeatedEntity;
                        return(response.ToHttpResponse(Logger, method));
                    }
                }

                DbContext.Add(user);
                int save = await DbContext.SaveChangesAsync();

                if (save == 0)
                {
                    response.ErrorCode = (int)ErrorHandler.ErrorCode.DbSaveNotDone;
                    return(response.ToHttpResponse(Logger, method));
                }
                var entity_list = new List <Setting> {
                    user
                }
                .Select(x => new
                {
                    x.id,
                    x.create_date,
                    x.creator_id,
                    x.type,
                    x.key,
                    x.value,
                    x.status
                }).First();
                response.Model     = entity_list;
                response.ErrorCode = (int)ErrorHandler.ErrorCode.OK;
            }
            catch (Exception ex)
            {
                LogHandler.LogError(Logger, response, method, ex);
            }
            return(response.ToHttpResponse(Logger, method));
        }
예제 #12
0
        public async Task <IActionResult> AddUser([FromBody] AddUserRequest request)
        {
            string method = nameof(AddUser);

            LogHandler.LogMethod(LogHandler.EventType.Call, Logger, method, request);
            SingleResponse <object> response = new SingleResponse <object>();

            try
            {
                if (!request.CheckValidation(response))
                {
                    return(response.ToHttpResponse(Logger, method));
                }

                var user = request.ToEntity();

                //var existingEntity = await DbContext.GetUnitcost(unit);
                //if (existingEntity != null)
                //{
                //    response.ErrorCode = (int)ErrorHandler.ErrorCode.AddRepeatedEntity;
                //    return response.ToHttpResponse(Logger, method);
                //}

                DbContext.Add(user);
                int save = await DbContext.SaveChangesAsync();

                if (save == 0)
                {
                    response.ErrorCode = (int)ErrorHandler.ErrorCode.DbSaveNotDone;
                    return(response.ToHttpResponse(Logger, method));
                }
                var entity_list = new List <User> {
                    user
                }
                .Select(x => new
                {
                    x.id,
                    x.create_date,
                    x.creator_id,
                    x.first_name,
                    x.last_name,
                    x.mobile,
                    x.status,
                    x.username
                }).First();
                response.Model     = entity_list;
                response.ErrorCode = (int)ErrorHandler.ErrorCode.OK;
            }
            catch (Exception ex)
            {
                LogHandler.LogError(Logger, response, method, ex);
            }
            return(response.ToHttpResponse(Logger, method));
        }
        public async Task <IActionResult> GetServiceCart([FromQuery] int addressId)
        {
            int?userId    = 0;
            var userStrId = this.User.FindFirstValue(ClaimTypes.Name);

            if (!string.IsNullOrWhiteSpace(userStrId))
            {
                userId = Convert.ToInt32(userStrId);
            }

            var response = new SingleResponse <CartPriceDetail>();

            try
            {
                response.Data   = (await _unit.ICart.GetCartDetail(userId.Value, addressId)).UserObject;
                response.Status = true;
            }
            catch (Exception ex)
            {
                response.Status  = false;
                response.Message = "There was an internal error, please contact to technical support.";
                ErrorTrace.Logger(LogArea.ApplicationTier, ex);
            }
            return(response.ToHttpResponse());
        }
예제 #14
0
        public async Task <IActionResult> PostEmployeeNoteAsync([FromBody] NoteRequest request)
        {
            var entity = request;

            entity.EntityTypeId = (int)EntityTypeEnum.Employee;
            entity.EntityId     = request.EmployeeId;
            var response = await EmployeeService.CreateEmployeeNoteAsync(entity);



            Docs docs = new Docs();

            docs.EntityId     = response.Model.NoteId;
            docs.EntityTypeId = (int)EntityTypeEnum.Note;

            var DOCSResponse = await EmployeeService.CreateDocsAsync(docs, typeof(Notes), request.NoteContent, request.FileRequest, (int)DocumentType.Note);

            if (DOCSResponse.DIdError)
            {
                throw new Exception("Error in create Document Notes" + response.Message);
            }


            SingleResponse <NoteRequest> res = new SingleResponse <NoteRequest>();

            res.Model = response.Model.ToEntity(null, request.EmployeeId, DOCSResponse.Model);

            return(res.ToHttpResponse());
        }
        public async Task <IActionResult> PostCreateAsync([FromForm] OrderRequestViewModel model)
        {
            int?userId    = 0;
            var userStrId = this.User.FindFirstValue(ClaimTypes.Name);

            if (!string.IsNullOrWhiteSpace(userStrId))
            {
                userId = Convert.ToInt32(userStrId);
            }

            var response = new SingleResponse <OrderResponseViewModel>();
            var result   = await _unit.IOrder.CreateOrder(userId.Value, model);

            if (result.HasSuccess)
            {
                response.Data    = result.UserObject;
                response.Message = "Success";
                response.Status  = true;
            }
            else
            {
                response.Data    = null;
                response.Message = "Error";
                response.Status  = false;
            }

            return(response.ToHttpResponse());
        }
예제 #16
0
        public async Task <IActionResult> AddEmailAccount([FromBody] EmailAccount NewEmailAccount)
        {
            var Response = new SingleResponse <EmailAccount>();

            try
            {
                await _IEmailAccountRepository.CreateEmailAccountAsync(NewEmailAccount);

                if (NewEmailAccount.EmailAccountId == 0)
                {
                    Response.DidError = true;
                    Response.Message  = $"The EmailAccount you are trying to add was already found in the database.";
                    _Logger.LogError(ControllerContext, Response.Message);
                }
                else
                {
                    Response.Message = $"{NewEmailAccount.EmailAccountId}";
                    Response.Model   = NewEmailAccount;
                    _Logger.LogInfo(ControllerContext, $"The EmailAccount with the id: {NewEmailAccount.EmailAccountId} was added to the database.");
                }
            }
            catch (Exception ex)
            {
                Response.DidError = true;
                Response.Message  = $"Internal Server Error. Error Message: {ex.Message}";
                _Logger.LogError(ControllerContext, Response.Message);
            }
            return(Response.ToHttpResponse());
        }
예제 #17
0
        public async Task <IActionResult> GetEmailAccountId(int id)
        {
            var Response = new SingleResponse <object>();

            try
            {
                if (!_IEmailAccountRepository.DoesEmailAccountExist(id))
                {
                    Response.DidError = true;
                    Response.Message  = $"The EmailAccount with the id: {id} was not found in the database.";
                    _Logger.LogError(ControllerContext, Response.Message);
                }
                else
                {
                    Response.Model = await _IEmailAccountRepository.GetEmailAccountByIdAsync(id);

                    Response.Message = $"Querying Account with the id: {id}.";
                    _Logger.LogInfo(ControllerContext, Response.Message);
                }
            }
            catch (Exception ex)
            {
                Response.DidError = true;
                Response.Message  = "Internal Server Error.";
                _Logger.LogError(ControllerContext, $"Error Message: {ex.Message}");
            }
            return(Response.ToHttpResponse());
        }
예제 #18
0
        public async Task <IActionResult> DeleteEmailAccountId(int id)
        {
            var Response = new SingleResponse <EmailAccount>();

            try
            {
                if (!_IEmailAccountRepository.DoesEmailAccountExist(id))
                {
                    Response.DidError = true;
                    Response.Message  = $"The EmailAccount with the id: {id} was not found in the database.";
                    _Logger.LogError(ControllerContext, Response.Message);
                }
                else
                {
                    EmailAccount EmailAccountToDelete = await _IEmailAccountRepository.GetEmailAccountByIdDefaultAsync(id);

                    await _IEmailAccountRepository.DeleteEmailAccountAsync(EmailAccountToDelete);

                    Response.Message = $"{EmailAccountToDelete.EmailAccountId}";
                    Response.Model   = EmailAccountToDelete;
                    _Logger.LogInfo(ControllerContext, $"EmailAccount with the id: {EmailAccountToDelete.EmailAccountId} has been deleted.");
                }
            }
            catch (Exception ex)
            {
                Response.DidError = true;
                Response.Message  = "Internal Server Error.";
                _Logger.LogError(ControllerContext, $"Error Message: {ex.Message}");
            }
            return(Response.ToHttpResponse());
        }
예제 #19
0
        public async Task <IActionResult> PostClientAsync([FromBody] Client request)
        {
            var response = new SingleResponse <Client>();

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

                // Add entity to repository
                _context.Clients.Add(request);

                // Save entity in database
                await _context.SaveChangesAsync();

                // Set the entity to response model
                response.Model = request;
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = "There was an internal error, please contact to technical support.";
            }
            return(response.ToHttpResponse());
        }
예제 #20
0
        public async Task <IActionResult> Login([FromBody] vmLoginUserRequest loggingUser)
        {
            var loginResponse = new SingleResponse <vmAuthorizedUserResponse>();

            try
            {
                var existedUserResponse = await _commonService.GetSingleUserForLoginAsync(loggingUser.Email);

                // if User does not exist or authentication fails
                if (existedUserResponse.Model == null || existedUserResponse.Model.UserID == 0 ||
                    !_passwordHasher.VerifyIdentityV3Hash(loggingUser.Password, existedUserResponse.Model.Password))
                {
                    throw new FamilyHubException(string.Format(CommonMessageDisplays.FailedAuthenticationMessage));
                }
                else
                {
                    // otherwise assign token and refreshtoken
                    loginResponse.Model = await _tokenService.AssignTokenToLoginUserAsync(existedUserResponse.Model);

                    loginResponse.Message = ResponseMessageDisplay.Success;
                }
            }
            catch (Exception ex)
            {
                loginResponse.SetError(ex);
            }


            return(loginResponse.ToHttpResponse());
        }
예제 #21
0
        public async Task <IActionResult> GetGameIdDefault(int id)
        {
            var Response = new SingleResponse <Game>();

            try
            {
                if (!_IGameRepository.DoesGameExist(id))
                {
                    Response.DidError = true;
                    Response.Message  = $"The Game with the id: {id} was not found in the database.";
                }
                else
                {
                    Response.Model = await _IGameRepository.GetGameByIdDefaultAsync(id);

                    Response.Message = $"Querying Game with the id: {id} with default information.";
                }
            }
            catch (Exception ex)
            {
                Response.DidError = true;
                Response.Message  = $"Internal Server Error. Error Message: {ex.Message}";
            }
            _Logger.LogInfo(ControllerContext, Response.Message);
            return(Response.ToHttpResponse());
        }
예제 #22
0
        public IActionResult AtualizarProduto([FromBody] ProdutoDTO produto)
        {
            var response = new SingleResponse <ProdutoDTO>();

            try
            {
                var produtoAtualizado = _produtoService.AtualizarProduto(MapearProdutoToEntity(produto));

                if (produtoAtualizado)
                {
                    response.Success = true;
                    response.Data    = produto;
                    response.Message = $"O produto foi atualizado com sucesso!";
                }
                else
                {
                    response.Success = false;
                    response.Message = $"Ocorreu um erro ao atualizar o produto com o identificador: {produto.Id}";
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = $"Erro interno não identificado. Detalhes: {ex.Message}";
            }

            return(response.ToHttpResponse());
        }
예제 #23
0
        public async Task <IActionResult> PutProduct(int id, Product product)
        {
            var response = new SingleResponse <Product>();

            if (id != product.Id)
            {
                return(BadRequest());
            }

            _context.Entry(product).State = EntityState.Modified;
            response.Model = product;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(id))
                {
                    response.DidError     = true;
                    response.ErrorMessage = "Product not found";
                }
                throw;
            }

            return(response.ToHttpResponse());
        }
예제 #24
0
        public IActionResult ExcluirProduto(string identificador)
        {
            var response = new SingleResponse <ProdutoDTO>();

            try
            {
                var produtoExcluido = _produtoService.ExcluirProduto(new Guid(identificador));

                if (produtoExcluido)
                {
                    response.Success = true;
                    response.Message = $"Produto excluido com sucesso!";
                }
                else
                {
                    response.Success = false;
                    response.Message = $"O produto com o identificador: {identificador} não foi encontrado!";
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = $"Erro interno não identificado. Detalhes: {ex.Message}";
            }

            return(response.ToHttpResponse());
        }
예제 #25
0
        public IActionResult ObterProdutoPeloId(string identificador)
        {
            var response = new SingleResponse <ProdutoDTO>();

            try
            {
                var produto = _produtoService.ObterProdutoPeloId(new Guid(identificador));

                if (produto != null)
                {
                    response.Data = MapearProdutoToDTO(produto);
                }
                else
                {
                    response.Success = false;
                    response.Message = $"O produto com o identificador: {identificador} não foi encontrado!";
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = $"Erro interno não identificado. Detalhes: {ex.Message}";
            }

            return(response.ToHttpResponse());
        }
예제 #26
0
        public IActionResult CriarNovoProduto([FromBody] ProdutoDTO produto)
        {
            var response = new SingleResponse <ProdutoDTO>();

            try
            {
                var identificador = _produtoService.AdicionarNovoProduto(MapearProdutoToEntity(produto));

                if (identificador != null)
                {
                    produto.Id       = identificador.ToString();
                    response.Success = true;
                    response.Data    = produto;
                    response.Message = $"O produto foi criado com sucesso!";
                }
                else
                {
                    response.Success = false;
                    response.Message = $"Ocorreu um erro ao criar o Produto";
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = $"Erro interno não identificado. Detalhes: {ex.Message}";
            }

            return(response.ToHttpResponse());
        }
예제 #27
0
        public async Task <IActionResult> AddGame([FromBody] Game NewGame)
        {
            var Response = new SingleResponse <Game>();

            try
            {
                await _IGameRepository.CreateGameAsync(NewGame);

                if (NewGame.GameId == 0)
                {
                    Response.DidError = true;
                    Response.Message  = $"The Game you are trying to add was already found in the database.";
                }
                else
                {
                    Response.Message = $"The Game with the id: {NewGame.GameId} was added to the database.";
                    Response.Model   = NewGame;
                }
            }
            catch (Exception ex)
            {
                Response.DidError = true;
                Response.Message  = $"Internal Server Error. Error Message: {ex.Message}";
            }
            _Logger.LogError(ControllerContext, Response.Message);
            return(Response.ToHttpResponse());
        }
예제 #28
0
        public async Task <IActionResult> UpdateEmailAccount([FromBody] EmailAccount UpdateEmailAccount)
        {
            var Response = new SingleResponse <EmailAccount>();

            try
            {
                int result = await _IEmailAccountRepository.UpdateEmailAccountAsync(UpdateEmailAccount);

                if (result == 0)
                {
                    Response.DidError = true;
                    Response.Message  = $"The Account with the id: {UpdateEmailAccount.EmailAccountId} was not found in the database.";
                    _Logger.LogError(ControllerContext, Response.Message);
                }
                else
                {
                    Response.Message = $"{UpdateEmailAccount.EmailAccountId}";
                    Response.Model   = UpdateEmailAccount;
                    _Logger.LogInfo(ControllerContext, $"EmailAccount with the id: {UpdateEmailAccount.EmailAccountId} has been updated.");
                }
            }
            catch (Exception ex)
            {
                Response.DidError = true;
                Response.Message  = "Internal Server Error.";
                _Logger.LogError(ControllerContext, $"Error Message: {ex.Message}");
            }
            return(Response.ToHttpResponse());
        }
        public async Task <IActionResult> PostClientOrderAsync([FromBody] ClientOrder request)
        {
            var response = new SingleResponse <ClientOrder>();

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

                // Add entity to repository
                _context.ClientOrders.Add(request);

                // Save entity in database
                await _context.SaveChangesAsync();

                // Set the entity to response model
                response.Model = request;
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.StackTrace;
                response.Message      = ex.Message;
            }
            return(response.ToHttpResponse());
        }
        public async Task <IActionResult> GetServiceByKG([FromQuery] int storeId, int ServiceId)
        {
            int    customerId = 0;
            string userId     = User.FindFirstValue(ClaimTypes.Name);

            if (!string.IsNullOrWhiteSpace(userId))
            {
                customerId = Convert.ToInt32(userId);
            }

            var response = new SingleResponse <ServiceByKgResponseViewModel>();
            var data     = await _unit.IService.GetServiceByKg(storeId, ServiceId, customerId);

            if (data.HasSuccess)
            {
                response.Data   = data.UserObject;
                response.Status = true;
            }
            else
            {
                response.Data   = null;
                response.Status = false;
            }
            return(response.ToHttpResponse());
        }