Exemple #1
0
        /// <summary>
        /// Update Customer by Id.
        /// </summary>
        /// <param name = "id"></param>
        /// <param name = "customer"></param>
        /// <returns></returns>
        /// <response code="200">Returns the newly-created item</response>
        /// <response code="400">If the item is null</response>

        public IHttpActionResult Put([FromBody] Customer customer, int id)
        {
            try
            {
                if (TimeUnit.Customers.Get(id) == null)
                {
                    return(NotFound());
                }

                List <string> errors = ValidateExtensions.ValidateCustomer(customer);

                if (errors.Count > 0)
                {
                    return(Content(HttpStatusCode.BadRequest, errors));
                }

                TimeUnit.Customers.Update(customer, id);
                //customer.Image = customer.ConvertAndSave();
                TimeUnit.Save();
                Utility.Log($"CUSTOMER CONTROLLER: Put Called on Customer, Successfully updated id: {id}.", "INFO");
                return(Ok(TimeFactory.Create(customer)));
            }
            catch (Exception ex)
            {
                Utility.Log($"CUSTOMER CONTROLLER: Put Cannot be called on Customer.", "ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }
Exemple #2
0
        public IHttpActionResult Post([FromBody] Employee employee)
        {
            try
            {
                List <string> errors = ValidateExtensions.ValidateEmployee(employee);

                if (errors.Count > 0)
                {
                    return(Content(HttpStatusCode.BadRequest, errors));
                }


                employee.Roles = TimeUnit.Roles.Get(employee.Roles.Id);
                employee.Image = employee.ConvertAndSave();
                TimeUnit.Employees.Insert(employee);
                TimeUnit.Save();
                Utility.Log($"EMPOLOYEE CONTROLLER: Post Called on Employee, Successfully added: {employee.FirstName + " " + employee.LastName}.", "INFO");
                return(Ok(TimeFactory.Create(employee)));
            }
            catch (Exception ex)
            {
                Utility.Log($"EMPOLOYEE CONTROLLER: Post Cannot be called on Employee.", "ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }
Exemple #3
0
        /// <summary>
        /// Insert Task.
        /// </summary>
        /// <param name="task"></param>
        /// <returns></returns>
        /// <response code="200">Returns the newly-created item</response>
        /// <response code="400">If the item is null</response>

        public IHttpActionResult Post([FromBody] Task task)
        {
            try
            {
                List <string> errors = ValidateExtensions.ValidateTask(task);

                if (errors.Count > 0)
                {
                    return(Content(HttpStatusCode.BadRequest, errors));
                }

                task.Day     = TimeUnit.Days.Get(task.Day.Id);
                task.Project = TimeUnit.Projects.Get(task.Day.Id);

                TimeUnit.Tasks.Insert(task);
                TimeUnit.Save();
                Utility.Log($"ROLE CONTROLLER: Post Called on Role, Successfully added: {task.Description}.", "INFO");
                return(Ok(TimeFactory.Create(task)));
            }
            catch (Exception ex)
            {
                Utility.Log($"ROLE CONTROLLER: Post Cannot be called on Role.", "ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }
        /// <summary>
        /// Update Team by Id.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="team"></param>
        /// <returns></returns>
        /// <response code="200">Returns the newly-created item</response>
        /// <response code="400">If the item is null</response>

        public IHttpActionResult Put([FromBody] Team team, string id)
        {
            List <string> errors = ValidateExtensions.ValidateTeam(team);

            if (errors.Count > 0)
            {
                return(Content(HttpStatusCode.BadRequest, errors));
            }


            try
            {
                if (TimeUnit.Teams.Get(id) == null)
                {
                    return(NotFound());
                }
                TimeUnit.Teams.Update(team, id);
                TimeUnit.Save();
                Utility.Log($"ROLE CONTROLLER: Put Called on Role, Successfully updated id: {id}.", "INFO");
                return(Ok(TimeFactory.Create(team)));
            }
            catch (Exception ex)
            {
                Utility.Log($"ROLE CONTROLLER: Put Cannot be called on Role.", "ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }
        /// <summary>
        /// Insert Project.
        /// </summary>
        /// <param name="project"></param>
        /// <returns></returns>
        /// <response code="200">Returns the newly-created item</response>
        /// <response code="400">If the item is null</response>

        public IHttpActionResult Post([FromBody] Project project)
        {
            try
            {
                List <string> errors = ValidateExtensions.ValidateProject(project);

                if (errors.Count > 0)
                {
                    return(Content(HttpStatusCode.BadRequest, errors));
                }

                project.Customer = TimeUnit.Customers.Get(project.CustomerId);
                project.Team     = TimeUnit.Teams.Get(project.TeamId);
                TimeUnit.Projects.Insert(project);
                TimeUnit.Save();
                Utility.Log($"PROJECT CONTROLLER: Post Called on Project, Successfully added: {project.Name}.", "INFO");
                return(Ok(TimeFactory.Create(project)));
            }

            catch (Exception ex)

            {
                Utility.Log($"PROJECT CONTROLLER: Post Cannot be called on Project.", "ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }
Exemple #6
0
        /// <summary>
        /// Insert Engagement.
        /// </summary>
        /// <param name="engagement"></param>
        /// <returns></returns>
        /// <response code="200">Returns the newly-created item</response>
        /// <response code="400">If the item is null</response>

        public IHttpActionResult Post([FromBody] Engagement engagement)
        {
            try
            {
                List <string> errors = ValidateExtensions.ValidateEngagements(engagement);

                if (errors.Count > 0)
                {
                    return(Content(HttpStatusCode.BadRequest, errors));
                }

                engagement.Team     = TimeUnit.Teams.Get(engagement.Team.Id);
                engagement.Role     = TimeUnit.Roles.Get(engagement.Role.Id);
                engagement.Employee = TimeUnit.Employees.Get(engagement.Employee.Id);

                TimeUnit.Engagements.Insert(engagement);
                TimeUnit.Save();
                Utility.Log($"ENGAGEMENT CONTROLLER: Post Called on Engagement, Successfully added: {engagement.Id}.", "INFO");
                return(Ok(TimeFactory.Create(engagement)));
            }

            catch (Exception ex)

            {
                Utility.Log($"ENGAGEMENT CONTROLLER: Post Cannot be called on Engagement.", "ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }
Exemple #7
0
        private Process ValidateExpMonthAndYear(ErrorModel errorModel, Process process)
        {
            if (ValidateExtensions.ValidateCreditCardExpMonth(process.ExpMonth.ToString(), errorModel))
            {
                var ExpMonth = process.ExpMonth.ToString();
                ExpMonth         = Convert.ToInt32(ExpMonth).ToString("D2");
                process.ExpMonth = Convert.ToInt32(ExpMonth);
            }

            if (ValidateExtensions.ValidateCreditCardExpYear(process.ExpYear.ToString(), errorModel))
            {
                var ExpYear = process.ExpYear.ToString();
                ExpYear          = Convert.ToInt32(ExpYear).ToString("D2");
                process.ExpMonth = Convert.ToInt32(ExpYear);
            }
            return(process);
        }
        /// <summary>
        /// Insert Role.
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        /// <response code="200">Returns the newly-created item</response>
        /// <response code="400">If the item is null</response>

        public IHttpActionResult Post([FromBody] Role role)
        {
            try
            {
                List <string> errors = ValidateExtensions.ValidateRole(role);

                if (errors.Count > 0)
                {
                    return(Content(HttpStatusCode.BadRequest, errors));
                }

                TimeUnit.Roles.Insert(role);
                TimeUnit.Save();
                Utility.Log($"ROLE CONTROLLER: Post Called on Role, Successfully added: {role.Name}.", "INFO");
                return(Ok(TimeFactory.Create(role)));
            }
            catch (Exception ex)
            {
                Utility.Log($"ROLE CONTROLLER: Post Cannot be called on Role.", "ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }
Exemple #9
0
        /// <summary>
        /// Insert Customer.
        /// </summary>
        /// <param name = "customer"></param>
        /// <returns></returns>
        /// <response code="200">Returns the newly-created item</response>
        /// <response code="400">If the item is null</response>

        public IHttpActionResult Post([FromBody] Customer customer)
        {
            try
            {
                List <string> errors = ValidateExtensions.ValidateCustomer(customer);

                if (errors.Count > 0)
                {
                    return(Content(HttpStatusCode.BadRequest, errors));
                }

                TimeUnit.Customers.Insert(customer);
                customer.Image = customer.ConvertAndSave();
                TimeUnit.Save();
                Utility.Log($"CUSTOMER CONTROLLER: Post Called on Customer, Successfully added: {customer.Name}.", "INFO");
                return(Ok(TimeFactory.Create(customer)));
            }
            catch (Exception ex)
            {
                Utility.Log($"CUSTOMER CONTROLLER: Post Cannot be called on Customer.", "ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }
Exemple #10
0
        /// <summary>
        /// Update Employee by Id.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="employee"></param>
        /// <returns></returns>
        /// <response code="200">Returns the newly-created item</response>
        /// <response code="400">If the item is null</response>

        public IHttpActionResult Put([FromBody] Employee employee, int id)
        {
            try
            {
                Employee oldEmployee = TimeUnit.Employees.Get(id);
                if (oldEmployee == null)
                {
                    return(NotFound());
                }
                employee = FillEmployeeWithOldData(employee, oldEmployee);

                employee.Roles = TimeUnit.Roles.Get(employee.Roles.Id);
                employee.Image = employee.ConvertAndSave();

                List <string> errors = ValidateExtensions.ValidateEmployee(employee);

                if (errors.Count > 0)
                {
                    return(Content(HttpStatusCode.BadRequest, errors));
                }

                if (TimeUnit.Employees.Get(id) == null)
                {
                    return(NotFound());
                }
                TimeUnit.Employees.Update(employee, id);
                TimeUnit.Save();
                Utility.Log($"EMPOLOYEE CONTROLLER: Put Called on Employee, Successfully updated id: {id}.", "INFO");
                return(Ok(TimeFactory.Create(employee)));
            }
            catch (Exception ex)
            {
                Utility.Log($"EMPOLOYEE CONTROLLER: Put Cannot be called on Employee.", "ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }
Exemple #11
0
        public async Task <dynamic> ProcessRequest(Request request)
        {
            request.isValid = true;
            var errorModel = new ErrorModel();


            try
            {
                var val = await _messageService.GetErrorMessage("ECord1");

                Logger.InformationLog($"In TransactionService.ProcessRequest, Process Request Start");

                var merchantInfoResult = await _paymentService.GetMerchantInfo(errorModel, request.MerchantInfo.MerchantKey, request.MerchantInfo.IpAddress, Convert.ToInt32(request.MerchantInfo.ProcessorId));

                if (errorModel.validationFailedMsg.Count > 0 || (errorModel.errors != null && errorModel.errors.Count > 0))
                {
                    GatewayResult Result = BuildValidationOrErrorFailedStatusReturnObject(errorModel, request.MerchantInfo.TransactionType);
                    return(Result);
                }

                Logger.InformationLog($"In TransactionController.ProcessRequest, GetMerchantInfo: " + JsonConvert.SerializeObject(merchantInfoResult));

                //If creditCardCryptogram is Not Null
                if (!string.IsNullOrEmpty(request.CreditCardCryptogram) && string.IsNullOrEmpty(request.CardNumber))
                {
                    var creditCardFromCryptogramResult = await _paymentService.GetCreditCardFromCryptogram(new PaymentDataFromCryptogramInput()
                    {
                        Cryptogram      = request.CreditCardCryptogram,
                        TransactionType = Convert.ToString(request.MerchantInfo.TransactionType)
                    });

                    if (creditCardFromCryptogramResult.Message != null)
                    {
                        request.CardNumber    = creditCardFromCryptogramResult.CardNumber;
                        request.CardExpMonth  = Convert.ToInt32(creditCardFromCryptogramResult.CardExpMonth);
                        request.CardExpYear   = Convert.ToInt32(creditCardFromCryptogramResult.CardExpYear);
                        request.CVV           = Convert.ToInt32(creditCardFromCryptogramResult.CardSecurityCode);
                        request.ConvFeeAmount = Convert.ToDecimal(creditCardFromCryptogramResult.FeeAmount);
                    }
                }

                //If token number is null then call tokenizer to generate token number
                if (string.IsNullOrEmpty(request.CreditCardToken) && !string.IsNullOrEmpty(request.CardNumber))
                {
                    request.CreditCardToken = _paymentService.GetTokenFromCreditCard(request.CardNumber);
                }

                var oldToken = request.CreditCardToken;

                //Check null values and MagData is empty
                var isNullProperties = (!string.IsNullOrEmpty(request.CreditCardToken) && request.CardExpMonth != null &&
                                        request.CardExpYear != null && string.IsNullOrEmpty(request.MagData));
                var process = new Process();
                if (isNullProperties)
                {
                    request.isValid  = false;
                    process.ExpMonth = request.CardExpMonth;
                    process.ExpYear  = request.CardExpYear;
                    process.CardType = CreditCardHelper.GetCreditCardType(request.CardNumber ?? _paymentService.GetCreditCardNumberFromToken(request.CreditCardToken));
                    process.Token    = request.CreditCardToken;

                    //GetUpdatedCardDetails
                    process = await _paymentService.GetUpdatedCardDetails(process);

                    //Re asign the expMonth, expYear and token
                    request.CardExpMonth    = process.ExpMonth;
                    request.CardExpYear     = process.ExpYear;
                    request.CreditCardToken = process.Token;
                }

                process = ValidateExpMonthAndYear(errorModel, process);

                if (errorModel.validationFailedMsg.Count > 0 || (errorModel.errors != null && errorModel.errors.Count > 0))
                {
                    GatewayResult Result = BuildValidationOrErrorFailedStatusReturnObject(errorModel, request.MerchantInfo.TransactionType);
                    return(Result);
                }

                ValidateExtensions.ValidateIpAddress(merchantInfoResult.IpAddress, errorModel);

                if (merchantInfoResult.AccountType == IndustryTypesEnum.ach.ToString())
                {
                    errorModel.errors.Add(string.Format("Invalid Account Type For Transaction ('{0}')", merchantInfoResult.AccountType));
                    return(null);
                }
                var ValidateHelper = new ValidateHelper();

                var orderId = new ValidateHelper().ValidateOrderIdAndGenerateNewOrderIdIfNeededAsync(request, merchantInfoResult, errorModel);

                process = await _paymentService.ValidateInitAndBuildProcessObject(request, merchantInfoResult, errorModel, process);

                if (!request.isValid)
                {
                    errorModel.validationFailedMsg.Add(new ValidationFailedMsg()
                    {
                        Key = "", Message = ""
                    });                                                                                      //On Hold
                }

                if (errorModel.errors.Count > 0 || errorModel.validationFailedMsg.Count > 0)
                {
                    GatewayResult Result = BuildValidationOrErrorFailedStatusReturnObject(errorModel, request.MerchantInfo.TransactionType);
                    return(Result);
                }

                if (!string.IsNullOrWhiteSpace(oldToken) && !string.IsNullOrWhiteSpace(process.Token))
                {
                    if (!oldToken.Equals(process.Token))
                    {
                        process.CardNumber = _paymentService.GenerateCardNumberUsingToken(process.Token.Trim());
                    }
                }

                if (process != null && request.OtherFields != null && request.OtherFields.Count > 0)
                {
                    _paymentService.ValidateAndAddCustomFields(process, request.OtherFields /*, info.processor*/);// On Hold
                }
                if (!string.IsNullOrWhiteSpace(request.CreditCardCryptogram))
                {
                    request.expireCryptogram = CryptogramHelper.ForceExpireCryptogramAsync(_config.GetSection("CryptogramApi").Value, request);
                }
                IndustryTypesEnum industryType = request.MerchantInfo.accountType.ParseEnum <IndustryTypesEnum>();


                return(process);
            }
            catch (Exception ex)
            {
                Logger.ErrorLog($"Exception In  TransactionService.ProcessRequest. exception={ex.Message}, Trace={ex.StackTrace}");
                throw ex;
            }
            finally
            {
                Logger.InformationLog($"Out  TransactionService.ProcessRequest, Process Request End");
            }
        }