Ejemplo n.º 1
0
        private StandardResponseObjectResult AddLabel(GitHubPostViewModel vm, WorkItem workItem)
        {
            ApiResponseViewModel response      = new ApiResponseViewModel();
            JsonPatchDocument    patchDocument = new JsonPatchDocument();

            if (!workItem.Fields["System.Tags"].ToString().Contains(vm.label))
            {
                patchDocument.Add(
                    new JsonPatchOperation()
                {
                    Operation = Operation.Add,
                    Path      = "/fields/System.Tags",
                    Value     = workItem.Fields["System.Tags"].ToString() + ", " + vm.label
                }
                    );

                WorkItem updateResult = _workItemsRepo.UpdateWorkItem(Convert.ToInt32(workItem.Id), patchDocument, vm);

                response.Message = "Label successfully update on work item";
                response.Success = true;
                response.Value   = updateResult;
            }
            else
            {
                response.Message = "Tag already exists on the work item";
                response.Success = true;
                response.Value   = null;
            }

            patchDocument = null;

            return(new StandardResponseObjectResult(response, StatusCodes.Status200OK));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Delete InvoiceDetail by Id
        /// </summary>
        /// <param name="id">ID of InvoiceDetail</param>
        /// <returns></returns>
        public ApiResponseViewModel Delete(int id)
        {
            var result   = new InvoiceDetail();
            var response = new ApiResponseViewModel
            {
                Code    = CommonConstants.ApiResponseSuccessCode,
                Message = null,
                Result  = null
            };

            try
            {
                var exists = _InvoiceDetailRepository.CheckContains(m => m.ID == id);
                if (exists)
                {
                    result = _InvoiceDetailRepository.Delete(id);
                    _unitOfWork.Commit();
                    response.Message = CommonConstants.DeleteSuccess;
                    response.Result  = result;
                }
                else
                {
                    response.Code    = CommonConstants.ApiResponseNotFoundCode;
                    response.Message = CommonConstants.NotFoundMessage;
                }
            }
            catch (Exception ex)
            {
                response.Code    = CommonConstants.ApiResponseExceptionCode;
                response.Message = CommonConstants.ErrorMessage + " " + ex.Message;
            }
            return(response);
        }
Ejemplo n.º 3
0
        public bool Add(ApiResponseViewModel sourceResponse)
        {
            var parsedResponse = CreateParsedResponse(sourceResponse);

            Responses.Push(parsedResponse);
            return(true);
        }
Ejemplo n.º 4
0
 public Response(ApiResponseViewModel sourceResponse)
 {
     SourceUrl     = sourceResponse.Url;
     SourceContent = sourceResponse.Content;
     Markups       = GetMarkups(sourceResponse.Content);
     Date          = DateTime.Now.ToLocalTime();
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Add new Tax value
        /// </summary>
        /// <param name="obj">Tax value</param>
        /// <returns></returns>
        public ApiResponseViewModel Add(User obj)
        {
            var result   = new User();
            var response = new ApiResponseViewModel
            {
                Code    = CommonConstants.ApiResponseSuccessCode,
                Message = null,
                Result  = null
            };

            try
            {
                obj.IsActive   = true;
                obj.LastOnline = DateTime.Now;
                result         = _userRepository.Add(obj);
                _unitOfWork.Commit();
                response.Message = CommonConstants.AddSuccess;
                response.Result  = result;
            }
            catch (Exception ex)
            {
                response.Code    = CommonConstants.ApiResponseExceptionCode;
                response.Message = CommonConstants.ErrorMessage + " " + ex.Message;
            }
            return(response);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Get Tax value by id
        /// </summary>
        /// <param name="id">ID of Tax value</param>
        /// <returns></returns>
        public ApiResponseViewModel GetById(int id)
        {
            var result   = new TypeViewModel();
            var response = new ApiResponseViewModel
            {
                Code    = CommonConstants.ApiResponseSuccessCode,
                Message = null,
                Result  = null
            };

            try
            {
                var exists = _TypeRepository.CheckContains(m => m.ID == id);
                if (exists)
                {
                    var tempResult = _TypeRepository.GetSingleById(id);
                    result.ID       = tempResult.ID;
                    result.TypeName = tempResult.TypeName;
                    result.IsActive = tempResult.IsActive ?? false;
                    response.Result = result;
                }
                else
                {
                    response.Code    = CommonConstants.ApiResponseNotFoundCode;
                    response.Message = CommonConstants.NotFoundMessage;
                }
            }
            catch (Exception ex)
            {
                response.Code    = CommonConstants.ApiResponseExceptionCode;
                response.Message = CommonConstants.ErrorMessage + " " + ex.Message;
            }

            return(response);
        }
Ejemplo n.º 7
0
        public static void ConfigureExceptionHandler(this IApplicationBuilder app)
        {
            app.UseExceptionHandler(configure =>
            {
                configure.Run(async handler =>
                {
                    var contextFeature = handler.Features.Get <IExceptionHandlerFeature>();
                    if (contextFeature != null)
                    {
                        var logger = handler.RequestServices.GetService <ILogger>();
                        logger.LogError(contextFeature.Error, $"Error in URL: {handler.Request.Path.Value}");
                        var apiResponse = new ApiResponseViewModel
                        {
                            Errors = new ErrorDetailsModel[]
                            {
                                new ErrorDetailsModel
                                {
                                    ErrorCode    = 500,
                                    ErrorMessage = contextFeature.Error.Message,
                                },
                            },
                        };

                        var jsonResponse = JsonConvert.SerializeObject(apiResponse);

                        handler.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                        await handler.Response.WriteAsync(jsonResponse);
                    }
                });
            });
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Add new invoice
        /// </summary>
        /// <param name="obj">invoice</param>
        /// <returns></returns>
        public ApiResponseViewModel Add(Invoice obj)
        {
            var result   = new Invoice();
            var response = new ApiResponseViewModel
            {
                Code    = CommonConstants.ApiResponseSuccessCode,
                Message = null,
                Result  = null
            };

            try
            {
                var currentDate = DateTime.Now;
                obj.InvoiceCode = "HD" + currentDate.Year + "" + currentDate.Month + "" + currentDate.Day + "" + currentDate.Hour + "" + currentDate.Minute;
                obj.CreatedDate = DateTime.Now;
                result          = _InvoiceRepository.Add(obj);
                _unitOfWork.Commit();
                response.Message = CommonConstants.AddSuccess;
                response.Result  = result;
            }
            catch (Exception ex)
            {
                response.Code    = CommonConstants.ApiResponseExceptionCode;
                response.Message = CommonConstants.ErrorMessage + " " + ex.Message;
            }
            return(response);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Update tax value
        /// </summary>
        /// <param name="obj">New Tax value</param>
        /// <returns></returns>
        public ApiResponseViewModel Update(Model.Models.Type obj)
        {
            var result   = new TypeViewModel();
            var response = new ApiResponseViewModel
            {
                Code    = CommonConstants.ApiResponseSuccessCode,
                Message = null,
                Result  = null
            };

            try
            {
                var exists = _TypeRepository.CheckContains(m => m.ID == obj.ID);
                if (exists)
                {
                    _TypeRepository.Update(obj);
                    _unitOfWork.Commit();
                    response.Message = CommonConstants.SaveSuccess;
                }
                else
                {
                    response.Code    = CommonConstants.ApiResponseNotFoundCode;
                    response.Message = CommonConstants.NotFoundMessage;
                }
            }
            catch (Exception ex)
            {
                response.Code    = CommonConstants.ApiResponseExceptionCode;
                response.Message = CommonConstants.ErrorMessage + " " + ex.Message;
            }

            return(response);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Get all Tax value
        /// </summary>
        /// <returns></returns>
        public ApiResponseViewModel GetAll()
        {
            var result   = new List <TypeViewModel>();
            var response = new ApiResponseViewModel
            {
                Code    = CommonConstants.ApiResponseSuccessCode,
                Message = null,
                Result  = null
            };

            try
            {
                result = _TypeRepository.GetAll().Where(m => m.IsActive == true).Select(m => new TypeViewModel
                {
                    ID       = m.ID,
                    TypeName = m.TypeName,
                    IsActive = m.IsActive ?? false
                }).ToList();
                response.Result = result;
            }
            catch (Exception ex)
            {
                response.Code    = CommonConstants.ApiResponseExceptionCode;
                response.Message = CommonConstants.ErrorMessage + " " + ex.Message;
            }
            return(response);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Make Tax value in-active by Id
        /// </summary>
        /// <param name="id">ID of Tax value</param>
        /// <returns></returns>
        public ApiResponseViewModel SetInActive(int id)
        {
            var result   = new Model.Models.Type();
            var response = new ApiResponseViewModel
            {
                Code    = CommonConstants.ApiResponseSuccessCode,
                Message = null,
                Result  = null
            };

            try
            {
                var exists = _TypeRepository.CheckContains(m => m.ID == id);
                if (exists)
                {
                    result          = _TypeRepository.GetSingleById(id);
                    result.IsActive = false;
                    _TypeRepository.Update(result);
                    _unitOfWork.Commit();
                    response.Message = CommonConstants.DeleteSuccess;
                    response.Result  = result;
                }
                else
                {
                    response.Code    = CommonConstants.ApiResponseNotFoundCode;
                    response.Message = CommonConstants.NotFoundMessage;
                }
            }
            catch (Exception ex)
            {
                response.Code    = CommonConstants.ApiResponseExceptionCode;
                response.Message = CommonConstants.ErrorMessage + " " + ex.Message;
            }
            return(response);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Get all account
        /// </summary>
        /// <returns></returns>
        public ApiResponseViewModel GetAll()
        {
            var result   = new List <AccountViewModel>();
            var response = new ApiResponseViewModel
            {
                Code    = CommonConstants.ApiResponseSuccessCode,
                Message = null,
                Result  = null
            };

            try
            {
                result = _accountRepository.GetAll().Where(m => m.IsActive == true).Select(m => new AccountViewModel
                {
                    ID          = m.ID,
                    AccountCode = m.AccountCode,
                    CategoryID  = m.CategoryID,
                    TaxValueID  = m.TaxValueID,
                    SH          = m.SH,
                    IsActive    = m.IsActive ?? false,
                    Category    = m.Category.CategoryName,
                    TaxValue    = m.TaxValue.Value
                }).ToList();
                response.Result = result;
            }
            catch (Exception ex)
            {
                response.Code    = CommonConstants.ApiResponseExceptionCode;
                response.Message = CommonConstants.ErrorMessage + " " + ex.Message;
            }
            return(response);
        }
Ejemplo n.º 13
0
        private StandardResponseObjectResult ReOpen(GitHubPostViewModel vm, int workItemId)
        {
            ApiResponseViewModel response      = new ApiResponseViewModel();
            JsonPatchDocument    patchDocument = new JsonPatchDocument();

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/System.State",
                Value     = _appSettings.Value.ADO_NewState
            }
                );

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/System.History",
                Value     = "Issue reopened"
            });

            WorkItem updateResult = _workItemsRepo.UpdateWorkItem(workItemId, patchDocument, vm);

            response.Message = "Issue successfully reopened";
            response.Success = true;
            response.Value   = null;

            patchDocument = null;

            return(new StandardResponseObjectResult(response, StatusCodes.Status200OK));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Get all Customer
        /// </summary>
        /// <returns></returns>
        public ApiResponseViewModel GetAll()
        {
            var result = new List<CustomerViewModel>();
            var response = new ApiResponseViewModel
            {
                Code = CommonConstants.ApiResponseSuccessCode,
                Message = null,
                Result = null
            };

            try
            {
                result = _customerRepository.GetAll().Where(m => m.IsActive == true).Select(m => new CustomerViewModel
                {
                    ID = m.ID,
                    CustomerTypeID = m.CustomerTypeID,
                    CustomerName = m.CustomerName,
                    CompanyID = m.CompanyID,
                    Address = m.Address,
                    PhoneNumber = m.PhoneNumber,
                    IsActive = m.IsActive ?? false,
                    Company = m.Company.CompanyName,
                    CustomerType = m.CustomerType.CustomerTypeName
                }).ToList();
                response.Result = result;
            }
            catch (Exception ex)
            {
                response.Code = CommonConstants.ApiResponseExceptionCode;
                response.Message = CommonConstants.ErrorMessage + " " + ex.Message;
            }
            return response;
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Add new Customer
        /// </summary>
        /// <param name="obj">Customer</param>
        /// <returns></returns>
        public ApiResponseViewModel Add(Customer obj)
        {
            var result = new Customer();
            var response = new ApiResponseViewModel
            {
                Code = CommonConstants.ApiResponseSuccessCode,
                Message = null,
                Result = null
            };

            try
            {
                result = _customerRepository.Add(obj);
                _unitOfWork.Commit();
                response.Message = CommonConstants.AddSuccess;
                response.Result = result;
            }
            catch (Exception ex)
            {
                response.Code = CommonConstants.ApiResponseExceptionCode;
                response.Message = CommonConstants.ErrorMessage + " " + ex.Message;
            }
            return response;

        }
Ejemplo n.º 16
0
        /// <summary>
        /// Get all Product
        /// </summary>
        /// <returns></returns>
        public ApiResponseViewModel GetAll()
        {
            var result   = new List <ProductViewModel>();
            var response = new ApiResponseViewModel
            {
                Code    = CommonConstants.ApiResponseSuccessCode,
                Message = null,
                Result  = null
            };

            try
            {
                result = _productRepository.GetAll().Where(m => m.IsActive == true).Select(m => new ProductViewModel
                {
                    ID          = m.ID,
                    ProductName = m.ProductName,
                    Description = m.Description,
                    UnitID      = m.UnitID,
                    UnitID2     = m.UnitID2,
                    IsActive    = m.IsActive ?? false,
                    UnitName    = _unitRepository.GetSingleById(m.UnitID).Value,
                    Unit2Name   = m.UnitID2 == null ? null : _unitRepository.GetSingleById(m.UnitID2 ?? 0).Value
                }).ToList();
                response.Result = result;
            }
            catch (Exception ex)
            {
                response.Code    = CommonConstants.ApiResponseExceptionCode;
                response.Message = CommonConstants.ErrorMessage + " " + ex.Message;
            }
            return(response);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Get all Department
        /// </summary>
        /// <returns></returns>
        public ApiResponseViewModel GetAll()
        {
            var result   = new List <DepartmentViewModel>();
            var response = new ApiResponseViewModel
            {
                Code    = CommonConstants.ApiResponseSuccessCode,
                Message = null,
                Result  = null
            };

            try
            {
                result = _departmentRepository.GetAll().Where(m => m.IsActive == true).Select(m => new DepartmentViewModel
                {
                    ID             = m.ID,
                    DepartmentName = m.DepartmentName,
                    CompanyID      = m.CompanyID,
                    CompanyName    = _companyRepository.GetSingleById(m.CompanyID)?.CompanyName,
                    Address        = m.Address,
                    IsActive       = m.IsActive ?? false,
                    Company        = m.Company.CompanyName
                }).ToList();
                response.Result = result;
            }
            catch (Exception ex)
            {
                response.Code    = CommonConstants.ApiResponseExceptionCode;
                response.Message = CommonConstants.ErrorMessage + " " + ex.Message;
            }
            return(response);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Check login
        /// </summary>
        /// <param name="obj">Username and password</param>
        /// <returns></returns>
        public ApiResponseViewModel CheckLogin(UserViewModel obj)
        {
            var result   = new UserViewModel();
            var response = new ApiResponseViewModel
            {
                Code    = CommonConstants.ApiResponseSuccessCode,
                Message = null,
                Result  = null
            };

            try
            {
                var user = _userRepository.GetUserByUsername(obj.Username);
                if (user == null)
                {
                    response.Code    = 2;
                    response.Message = "Your account is not exists.";
                }
                else
                {
                    if (user.IsActive != true)
                    {
                        response.Code    = 3;
                        response.Message = "Your account is inactive. Please contact adminitrator.";
                    }
                    else
                    {
                        if (Utilities.Md5(obj.Password).ToLower() != user.Password.ToLower())
                        {
                            response.Code    = 4;
                            response.Message = "Password is incorect.";
                        }
                        else
                        {
                            result.ID           = user.ID;
                            result.Username     = user.Username;
                            result.Password     = user.Password;
                            result.Fullname     = user.Fullname;
                            result.CompanyID    = user.CompanyID;
                            result.Image        = user.Image;
                            result.Age          = user.Age;
                            result.Address      = user.Address;
                            result.AboutMe      = user.AboutMe;
                            result.LastOnline   = Common.Utilities.TimeAgo(user.LastOnline);
                            result.IsActive     = user.IsActive ?? false;
                            result.Company      = user.Company.CompanyName;
                            result.UserAccounts = _userAccountRepository.GetListUserAccountByUserID(user.ID);
                            response.Result     = result;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                response.Code    = CommonConstants.ApiResponseExceptionCode;
                response.Message = CommonConstants.ErrorMessage + " " + ex.Message;
            }
            return(response);
        }
        public ActionResult GetCount()
        {
            ApiResponseViewModel response = new ApiResponseViewModel();

            WorkItemQueryResult results = _workItemsRepo.QueryWorkItems();
            int count = results != null?results.WorkItems.Count() : 0;

            return(new StandardResponseObjectResult(count, StatusCodes.Status200OK));
        }
Ejemplo n.º 20
0
        protected JsonResult ApiResponse(object data)
        {
            var apiResponse = new ApiResponseViewModel
            {
                Data = data,
            };

            return(Json(apiResponse));
        }
        public async Task <IActionResult> ApiResponse()
        {
            string value = await HttpClientHelper.GetContentsFromApi();

            ApiResponseViewModel responseViewModel = new ApiResponseViewModel();

            responseViewModel.ArrayValues = JArray.Parse(value);
            return(View(responseViewModel));
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Save all invoices
        /// </summary>
        /// <param name="lst">invoices</param>
        /// <returns></returns>
        public ApiResponseViewModel SaveAll(List <InvoiceInput> lst)
        {
            var result   = new List <InvoiceDetail>();
            var response = new ApiResponseViewModel
            {
                Code    = CommonConstants.ApiResponseSuccessCode,
                Message = null,
                Result  = null
            };

            try
            {
                foreach (var item in lst)
                {
                    decimal totalValue  = 0;
                    var     customerID  = 0;
                    var     inOut       = false;
                    var     invoiceCode = "";
                    foreach (var sub in item.details)
                    {
                        var obj = new InvoiceDetail();
                        obj.ID           = 0;
                        obj.InvoiceID    = item.id;
                        obj.Value        = sub.Value;
                        obj.DepartmentID = sub.DepartmentID;
                        obj.CategoryID   = sub.CategoryID;
                        obj.TaxValueID   = sub.TaxValue;
                        obj.IsActive     = true;
                        obj.TaxValueID   = sub.TaxValue;
                        result.Add(_InvoiceDetailRepository.Add(obj));

                        totalValue += sub.Value;
                        customerID  = sub.CustomerID;
                        inOut       = sub.InOut;
                        invoiceCode = sub.InvoiceCode;
                    }
                    var invoice = _InvoiceRepository.GetSingleById(item.id);
                    invoice.InvoiceCode = invoiceCode;
                    invoice.InOut       = inOut;
                    invoice.Value       = totalValue;
                    invoice.CustomerID  = customerID;
                    invoice.IsActive    = true;
                    _InvoiceRepository.Update(invoice);
                }
                _unitOfWork.Commit();
                response.Message = CommonConstants.AddSuccess;
                response.Result  = result;
            }
            catch (Exception ex)
            {
                response.Code    = CommonConstants.ApiResponseExceptionCode;
                response.Message = CommonConstants.ErrorMessage + " " + ex.Message;
            }
            return(response);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Get all Invoice
        /// </summary>
        /// <returns></returns>
        public ApiResponseViewModel Filter(string fromDate, string toDate)
        {
            var result   = new List <InvoiceDetailViewModel>();
            var response = new ApiResponseViewModel
            {
                Code    = CommonConstants.ApiResponseSuccessCode,
                Message = null,
                Result  = null
            };

            try
            {
                var invoiceDetails = _InvoiceDetailRepository.GetMulti(m => m.IsActive == true);
                var fromDateValue  = !string.IsNullOrEmpty(fromDate) ? DateTime.Parse(fromDate) : DateTime.Now;
                var toDateValue    = !string.IsNullOrEmpty(toDate) ? DateTime.Parse(toDate) : DateTime.Now;
                foreach (var idetail in invoiceDetails)
                {
                    var invoice = _InvoiceRepository.GetMulti(
                        m => m.IsActive == true &&
                        m.ID == idetail.InvoiceID &&
                        (m.CreatedDate >= fromDateValue) &&
                        (m.CreatedDate <= toDateValue)
                        //&& (string.IsNullOrEmpty(fromDate.Trim()) || m.CreatedDate >= fromDateValue)
                        //&& (string.IsNullOrEmpty(toDate.Trim()) || m.CreatedDate <= toDateValue)
                        ).FirstOrDefault();
                    if (invoice != null)
                    {
                        var obj = new InvoiceDetailViewModel
                        {
                            ID          = invoice.ID,
                            InvoiceCode = invoice.InvoiceCode,
                            CreateDate  = invoice.CreatedDate.ToShortDateString(),
                            CustomerID  = int.Parse(invoice.CustomerID.ToString()),
                            Customer    = _CustomerRepository.GetSingleById(int.Parse(invoice.CustomerID.ToString())).CustomerName,
                            Category    = idetail.Category.CategoryName,
                            InOut       = invoice.InOut ?? false,
                            Status      = invoice.Status,
                            Value       = decimal.Parse(idetail.Value.ToString()).ToString("###,##"),
                            IsActive    = idetail.IsActive ?? false,
                            TaxValue    = idetail.TaxValue.Value.ToString()
                                          //InvoiceDetails = _InvoiceDetailRepository.GetListInvoiceDetailsByInvoiceID(idetail.ID)
                        };
                        result.Add(obj);
                    }
                }
                response.Result = result;
            }
            catch (Exception ex)
            {
                response.Code    = CommonConstants.ApiResponseExceptionCode;
                response.Message = CommonConstants.ErrorMessage + " " + ex.Message;
            }
            return(response);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Get all Tax value with pagging
        /// </summary>
        /// <param name="page">Current page</param>
        /// <param name="pageSize">Page size</param>
        /// <returns></returns>
        public ApiResponseViewModel GetAllWithPagging(int?page, int pageSize)
        {
            var result        = new List <UserViewModel>();
            var paginationSet = new PaginationSet <UserViewModel>();
            var response      = new ApiResponseViewModel
            {
                Code    = CommonConstants.ApiResponseSuccessCode,
                Message = null,
                Result  = null
            };

            try
            {
                var currentPage = page ?? 1;
                int totalRow    = 0;
                var query       = _userRepository.GetAll().Where(m => m.IsActive == true);
                totalRow = query.Count();

                result = query.OrderBy(x => x.ID).Skip((currentPage - 1) * pageSize)
                         .Take(pageSize)
                         .Select(m => new UserViewModel
                {
                    ID           = m.ID,
                    Username     = m.Username,
                    Password     = m.Password,
                    Fullname     = m.Fullname,
                    CompanyID    = m.CompanyID,
                    Image        = m.Image,
                    Age          = m.Age,
                    Address      = m.Address,
                    AboutMe      = m.AboutMe,
                    LastOnline   = Common.Utilities.TimeAgo(m.LastOnline),
                    IsActive     = m.IsActive ?? false,
                    Company      = m.Company.CompanyName,
                    UserAccounts = _userAccountRepository.GetListUserAccountByUserID(m.ID)
                })
                         .ToList();

                paginationSet = new PaginationSet <UserViewModel>()
                {
                    Items      = result,
                    Page       = currentPage,
                    TotalCount = result.Count(),
                    TotalPages = (int)Math.Ceiling((decimal)totalRow / pageSize)
                };
                response.Result = paginationSet;
            }
            catch (Exception ex)
            {
                response.Code    = CommonConstants.ApiResponseExceptionCode;
                response.Message = CommonConstants.ErrorMessage + " " + ex.Message;
            }
            return(response);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Get all Tax value with pagging
        /// </summary>
        /// <param name="page">Current page</param>
        /// <param name="pageSize">Page size</param>
        /// <returns></returns>
        public ApiResponseViewModel GetAllWithPagging(int?page, int pageSize)
        {
            var result        = new List <UserAccountViewModel>();
            var paginationSet = new PaginationSet <UserAccountViewModel>();
            var response      = new ApiResponseViewModel
            {
                Code    = CommonConstants.ApiResponseSuccessCode,
                Message = null,
                Result  = null
            };

            try
            {
                var currentPage = page ?? 1;
                int totalRow    = 0;
                var query       = _userAccountRepository.GetAll().Where(m => m.IsActive == true);
                totalRow = query.Count();

                result = query.OrderBy(x => x.ID).Skip((currentPage - 1) * pageSize)
                         .Take(pageSize)
                         .Select(m => new UserAccountViewModel
                {
                    ID              = m.ID,
                    UserID          = m.UserID,
                    AccountID       = m.AccountID,
                    IsActive        = m.IsActive ?? false,
                    AccountCode     = m.Account.AccountCode,
                    AccountSH       = m.Account.SH,
                    AccountTaxVaue  = m.Account.TaxValue.Value,
                    AccountCategory = m.Account.Category.CategoryName,
                    UserName        = m.User.Username,
                    UserImage       = m.User.Username,
                    UserCompany     = m.User.Fullname,
                    FullName        = m.User.Fullname,
                })
                         .ToList();

                paginationSet = new PaginationSet <UserAccountViewModel>()
                {
                    Items      = result,
                    Page       = currentPage,
                    TotalCount = result.Count(),
                    TotalPages = (int)Math.Ceiling((decimal)totalRow / pageSize)
                };
                response.Result = paginationSet;
            }
            catch (Exception ex)
            {
                response.Code    = CommonConstants.ApiResponseExceptionCode;
                response.Message = CommonConstants.ErrorMessage + " " + ex.Message;
            }
            return(response);
        }
Ejemplo n.º 26
0
        private StandardResponseObjectResult CreateNew(GitHubPostViewModel vm)
        {
            ApiResponseViewModel response = new ApiResponseViewModel();

            WorkItem createResult = this.CreateNewWorkItem(vm);

            response.Message = "Successfully created work item";
            response.Success = true;
            response.Value   = createResult;

            return(new StandardResponseObjectResult(response, StatusCodes.Status200OK));
        }
Ejemplo n.º 27
0
        public async Task Invoke(HttpContext context)
        {
            try
            {
                await _delegate(context);
            }
            catch (Exception ex)
            {
                var response = context.Response;

                response.ContentType = "application/json";

                ApiResponseViewModel responseViewModel;

                switch (ex)
                {
                case EntityNotFoundException error:
                    response.StatusCode = (int)HttpStatusCode.NotFound;
                    responseViewModel   = new ApiResponseViewModel(false, error.Message);
                    break;

                case EmptyFileException error:
                    response.StatusCode = (int)HttpStatusCode.BadRequest;
                    responseViewModel   = new ApiResponseViewModel(false, error.Message);
                    break;

                case LoginFailureException error:
                    response.StatusCode = (int)HttpStatusCode.BadRequest;
                    responseViewModel   = new ApiResponseViewModel(false, error.Message);
                    break;

                case UserRegistrationException error:
                    response.StatusCode = (int)HttpStatusCode.BadRequest;
                    responseViewModel   = new ApiResponseViewModel(false, error.Message);
                    break;

                case UpdateEntityException error:
                    response.StatusCode = (int)HttpStatusCode.Conflict;
                    responseViewModel   = new ApiResponseViewModel(false, error.Message);
                    break;

                default:

                    // Unhandled Exception

                    response.StatusCode = (int)HttpStatusCode.InternalServerError;
                    responseViewModel   = new ApiResponseViewModel(false, ex.Message);
                    break;
                }

                await response.WriteAsync(JsonSerializer.Serialize(responseViewModel));
            }
        }
Ejemplo n.º 28
0
        public async Task <IActionResult> Create([FromForm] CreateDataViewModel measurement)
        {
            if (!ModelState.IsValid)
            {
                return(View(measurement));
            }
            if (ModelState.IsValid)
            {
                var modelForCreation = new SensorDto {
                    Id          = measurement.LocationIdentifier,
                    Light       = measurement.Light,
                    Temperature = measurement.Temperature,
                    TimeStamp   = DateTime.Now.ToLongTimeString()
                };

                var serializedModel = JsonConvert.SerializeObject(modelForCreation);

                var apiClient = await _sensorHttpClient.GetClient();

                using (apiClient)
                {
                    try
                    {
                        var response = await apiClient.PostAsync("api/SensorDatas",
                                                                 new StringContent(serializedModel, System.Text.Encoding.Unicode, "application/json"));

                        if (response.IsSuccessStatusCode)
                        {
                            return(RedirectToAction("Index"));
                        }
                        else
                        {
                            var m = new ApiResponseViewModel();
                            m.Content    = response.Content.ToString();
                            m.Message    = response.Headers.ToString();
                            m.StatusCode = response.StatusCode.ToString();

                            return(RedirectToAction("ShowOtherStatusCodesFromApi", m));
                        }
                    }
                    catch (HttpRequestException e)
                    {
                        throw new HttpRequestException(e.Message);
                    }
                    catch (ArgumentNullException n)
                    {
                        throw new ArgumentNullException(n.Message);
                    }
                }
            }
            return(View(measurement));
        }
Ejemplo n.º 29
0
        private StandardResponseObjectResult UpdateEdited(GitHubPostViewModel vm, WorkItem workItem)
        {
            ApiResponseViewModel response      = new ApiResponseViewModel();
            JsonPatchDocument    patchDocument = new JsonPatchDocument();

            //if title changes
            if (!workItem.Fields["System.Title"].Equals(vm.title + " (GitHub Issue #" + vm.number.ToString() + ")"))
            {
                patchDocument.Add(
                    new JsonPatchOperation()
                {
                    Operation = Operation.Add,
                    Path      = "/fields/System.Title",
                    Value     = vm.title + " (GitHub Issue #" + vm.number.ToString() + ")"
                });
            }


            // if description changed
            if (!workItem.Fields["System.Description"].Equals(vm.body))
            {
                patchDocument.Add(
                    new JsonPatchOperation()
                {
                    Operation = Operation.Add,
                    Path      = "/fields/System.Description",
                    Value     = vm.body
                }
                    );
            }

            // if nothing in the patch document, then don't update
            if (patchDocument.Count > 0)
            {
                WorkItem updateResult = _workItemsRepo.UpdateWorkItem((int)workItem.Id, patchDocument, vm);

                response.Message = "Work item successfully updated";
                response.Success = true;
                response.Value   = updateResult;

                patchDocument = null;
            }
            else
            {
                response.Message = "No changes to be made";
                response.Success = true;
                response.Value   = null;
            }

            return(new StandardResponseObjectResult(response, StatusCodes.Status200OK));
        }