public IHttpActionResult Post(QueryDetailViewModel queryDetailVM)
        {
            var queryDetail = new QueryDetail
            {
                Query       = queryDetailVM.Query,
                Active      = queryDetailVM.Active,
                Answer      = queryDetailVM.Answer,
                Contact     = queryDetailVM.Contact,
                CreatedDate = queryDetailVM.CreatedDate,
                Email       = queryDetailVM.Email,
                Id          = queryDetailVM.Id,
                Name        = queryDetailVM.Name,
                Status      = queryDetailVM.Status
            };

            this.queryService.Save(queryDetail, queryDetailVM.SendReplyEmail);
            return(Get());
        }
Exemple #2
0
        public DataSourceResponse <QueryDetailViewModel> ReadQueryDetails(DataSourceRequest request, IIdentity identity)
        {
            string cmdText = @"
                SELECT c.[Name], ur.RoleId
                FROM Customer c JOIN AspNetUserRoles ur ON c.UserId = ur.UserId
                WHERE c.UserId = @UserId";

            var currentUserId = identity.GetUserId();
            var roles         = this.userService.GetRoles();

            WebApplication.Models.Role.Role currentRole;
            string currentName = string.Empty;

            this.ReadDataSingle(dataReader =>
            {
                string currentRoleId = dataReader["RoleId"].ToString();
                currentRole          = roles[currentRoleId];
                currentName          = dataReader["Name"].ToString();
            }, cmdText, new SqlParameter("UserId", currentUserId));

            ServerFilterInfo yearFilterInfo = request.ServerFiltering.FilterCollection.Where(f => f.Field == "Year").SingleOrDefault();
            int year = Convert.ToInt32(yearFilterInfo.Value);
            ServerFilterInfo monthFilterInfo = request.ServerFiltering.FilterCollection.Where(f => f.Field == "Month").SingleOrDefault();
            int month     = Convert.ToInt32(monthFilterInfo.Value);
            var shipments = this.DbContext.Shipments.Where(s => s.UserId == currentUserId && s.Date.Year == year && s.Date.Month == month).ToList();

            IDictionary <int, string>    customers    = new Dictionary <int, string>();
            IList <QueryDetailViewModel> responseData = new List <QueryDetailViewModel>();

            foreach (var shipment in shipments)
            {
                var viewModel = new QueryDetailViewModel
                {
                    PurchaseId   = shipment.ShipmentId,
                    Year         = year,
                    Month        = month,
                    ShipmentDate = shipment.Date
                };

                if (shipment.CustomerId.HasValue)
                {
                    if (customers.ContainsKey(shipment.CustomerId.Value))
                    {
                        viewModel.CustomerName = customers[shipment.CustomerId.Value];
                    }
                    else
                    {
                        var customer = this.DbContext.Customers.Where(c => c.CustomerId == shipment.CustomerId.Value).SingleOrDefault();
                        if (customer != null)
                        {
                            customers.Add(shipment.CustomerId.Value, customer.Name);
                            viewModel.CustomerName = customer.Name;
                        }
                    }
                }
                else
                {
                    viewModel.CustomerName = currentName;
                }

                var shipmentDetails = this.DbContext.ShipmentDetails.Where(d => d.ShipmentId == shipment.ShipmentId).ToList();
                foreach (var shipmentDetail in shipmentDetails)
                {
                    viewModel.TotalAmount += shipmentDetail.SubtotalAmount;
                }

                responseData.Add(viewModel);
            }

            var response = new DataSourceResponse <QueryDetailViewModel> {
                TotalRowCount = responseData.Count
            };

            if (request.ServerPaging != null)
            {
                int skip = Math.Max(request.ServerPaging.PageSize * (request.ServerPaging.Page - 1), val2: 0);
                response.DataCollection = responseData.OrderBy(v => v.PurchaseId).Skip(skip).Take(request.ServerPaging.PageSize).ToList();
            }

            return(response);
        }