Beispiel #1
0
        /// <summary>
        /// To get request details from database
        /// </summary>
        /// <param name="requestId">id of request</param>
        /// <returns>details of the request</returns>
        public RequestDetailsViewModel GetRequestDetails(int requestId)
        {
            using (RMSDbContext context = new RMSDbContext())
            {
                var requestDetails = context.USP_GetRequestDetails(requestId).Select(s => new RequestDetailsViewModel()
                {
                    CompanyName     = s.CompanyName,
                    CreatedBy       = s.DisplayName,
                    CreatedOn       = s.CreatedOn.ToString(Constants.DATE_FORMAT),
                    CustomerContact = s.CustomerContact,
                    CustomerName    = s.CustomerName,
                    ModelNumber     = s.ModelNumber,
                    ProblemDetails  = s.ProblemDetails,
                    RequestId       = s.RequestId,
                    Status          = s.StatusName,
                    StatusId        = s.StatusId ?? 0,
                    CustomerAddress = s.FullAddress,
                    Expense         = s.Expense
                }).SingleOrDefault();

                if (requestDetails != null)
                {
                    requestDetails.RequestChangeLog = context.USP_GetRequestStatusChangeLog(requestId).Select(cl =>
                                                                                                              new RequestStatusLogViewModel()
                    {
                        Comments      = cl.Comments,
                        ModifiedBy    = cl.ModifiedBy,
                        ModifiedOn    = cl.ModifiedOn.ToString(Constants.DATE_TIME_FORMAT),
                        UpdatedStatus = cl.StatusName
                    }).ToList();
                }

                return(requestDetails);
            }
        }
Beispiel #2
0
 public string GetUserRoles(string userName, string password)
 {
     using (RMSDbContext context = new RMSDbContext())
     {
         var roleName = context.USP_AuthenticateUser(userName, password).Select(s => s.RoleName).SingleOrDefault();
         return(roleName);
     }
 }
Beispiel #3
0
 /// <summary>
 /// To get userid from username
 /// </summary>
 /// <param name="userName">username</param>
 /// <returns></returns>
 public int?GetUserId(string userName)
 {
     using (RMSDbContext context = new RMSDbContext())
     {
         var userId = context.UserMaster.Where(s => s.UserName == userName).Select(s => s.UserId).SingleOrDefault();
         return(userId);
     }
 }
Beispiel #4
0
 /// <summary>
 /// To get approved requests list
 /// </summary>
 /// <param name="pageNumber">page number</param>
 /// <returns></returns>
 public DashboardViewModel GetApprovedRequests(int pageNumber)
 {
     using (RMSDbContext context = new RMSDbContext())
     {
         var requestList = GetRequestListForDashboar(context, pageNumber, null, (int)StatusEnum.Approved);
         return(requestList);
     }
 }
Beispiel #5
0
 /// <summary>
 /// To get request list attended by logged in user
 /// </summary>
 /// <param name="userId">id of logged in user</param>
 /// <param name="pageNumber">page number </param>
 /// <returns>request list</returns>
 public DashboardViewModel GetMyAttendedRepairRequest(int userId, int pageNumber)
 {
     using (RMSDbContext context = new RMSDbContext())
     {
         var requestList = GetRequestListForDashboar(context, pageNumber, userId, null);
         return(requestList);
     }
 }
Beispiel #6
0
        //to get individual request count based on input status id
        private ChartItemViewModel GetRequestCountByStatus(RMSDbContext context, int statusId)
        {
            var requestCount = context.USP_GetRequestCountByStatus(statusId)
                               .Select(s => new ChartItemViewModel()
            {
                Lable = s.StatusName,
                Value = s.RequestCount ?? 0
            }).SingleOrDefault();

            return(requestCount);
        }
Beispiel #7
0
        //insert log of status update in database
        private void UpdateStatusLog(RMSDbContext context, int requestId, int statusId, int modifiedBy, string comments)
        {
            var statusChangeLog = new RequestStatusChangeLog()
            {
                ModifiedBy = modifiedBy,
                ModifiedOn = DateTime.Now,
                RequestId  = requestId,
                StatusId   = statusId,
                Comments   = comments
            };

            context.RequestStatusChangeLog.Add(statusChangeLog);
        }
Beispiel #8
0
        /// <summary>
        /// To get states list from db
        /// </summary>
        /// <returns></returns>
        public List <StateDropDownViewModel> GetStates()
        {
            using (RMSDbContext context = new RMSDbContext())
            {
                var stateList = context.StateMaster.Select(s => new StateDropDownViewModel()
                {
                    StateId   = s.StateId,
                    StateName = s.StateName
                }).ToList();

                return(stateList);
            }
        }
Beispiel #9
0
        /// <summary>
        /// Method to get cities list based on state id
        /// </summary>
        /// <returns></returns>
        public List <CityDropDownViewModel> GetCities(int stateId)
        {
            using (RMSDbContext context = new RMSDbContext())
            {
                var cityList = context.CityMaster.Where(c => c.StateId == stateId).Select(c => new CityDropDownViewModel()
                {
                    CityId   = c.CityId,
                    StateId  = c.StateId,
                    CityName = c.CityName
                }).ToList();

                return(cityList);
            };
        }
Beispiel #10
0
        //To get average response time
        private double?CalculateAvgResponseTime(RMSDbContext context)
        {
            double?averageResponseTime;
            var    responseTimeList = context.USP_GetRequestStartEndDate().Select(r => (r.ClosedOn - r.CreatedOn).TotalDays).ToList();

            if (responseTimeList.Count > 0)
            {
                averageResponseTime = responseTimeList.Sum() / responseTimeList.Count;
            }
            else
            {
                averageResponseTime = null;
            }
            return(averageResponseTime);
        }
Beispiel #11
0
        //Common method to update status
        private void UpdateStatus(UpdateRequestStatusViewModel updateRequestStatusViewModel, int statusIdToUpdate, bool allowPreviousStatus = false)
        {
            var updateStatusResponse = new UpdateStatusResponseViewModel();

            using (RMSDbContext context = new RMSDbContext())
            {
                var requestDetails = context.RepairRequestDetails.Where(s => s.RequestId == updateRequestStatusViewModel.RequestId).Single();
                if (!allowPreviousStatus && requestDetails.StatusId >= statusIdToUpdate)
                {
                    throw new Exception("Status of the request " + requestDetails.RequestId + " is already moved forward.");
                }
                requestDetails.StatusId = statusIdToUpdate;
                UpdateStatusLog(context, requestDetails.RequestId, statusIdToUpdate, updateRequestStatusViewModel.UserId, updateRequestStatusViewModel.Comment);
                context.SaveChanges();
            }
        }
Beispiel #12
0
        /// <summary>
        /// Method to verify user credentials in database
        /// </summary>
        /// <param name="userName">username</param>
        /// <param name="password">password</param>
        /// <returns></returns>
        public UserDetailsViewModel CheckUserCredentials(string userName, string password)
        {
            using (RMSDbContext context = new RMSDbContext())
            {
                var userDetails = context.USP_AuthenticateUser(userName, password).Select(
                    u => new UserDetailsViewModel()
                {
                    UserId             = u.UserId,
                    UserName           = u.UserName,
                    EmailId            = u.EmailId,
                    RoleName           = u.RoleName,
                    DisplayName        = u.DisplayName,
                    AuthorizationToken = CryptoHelper.Encrypt(String.Concat(userName, Constants.TOKEN_SEPARATOR, password), Constants.ENCRYPTION_KEY)
                }).SingleOrDefault();

                return(userDetails);
            }
        }
Beispiel #13
0
        /// <summary>
        /// To get necessary details to show graphs
        /// </summary>
        /// <param name="userId">id of logged in user</param>
        /// <returns>details required to show all 3 graphs</returns>
        public ReportViewModel GetReportDetails(int userId)
        {
            using (RMSDbContext context = new RMSDbContext())
            {
                var reportDetails = new ReportViewModel();
                reportDetails.AverageResponseTime = CalculateAvgResponseTime(context);

                //To get the request details created by logged in user
                var myRequestDetails = context.USP_GetMyRequsetCountForReport(userId)
                                       .Select(s => new ChartItemViewModel
                {
                    Lable = s.CreatedDate,
                    Value = s.RequestCount ?? 0
                }).ToList();
                //Transfer request details into form required for Chart
                reportDetails.BarChartDetails = new ChartsViewModel()
                {
                    ChartData  = myRequestDetails.Select(rd => rd.Value).ToList(),
                    ChartLable = myRequestDetails.Select(rd => rd.Lable).ToList()
                };

                var requestStatusCountDetails = new List <ChartItemViewModel>();
                var pendingItemDetails        = GetRequestCountByStatus(context, (int)StatusEnum.Pending);
                requestStatusCountDetails.Add(pendingItemDetails);
                var completedItemDetails = GetRequestCountByStatus(context, (int)StatusEnum.Completed);
                requestStatusCountDetails.Add(completedItemDetails);
                var approvedItemDetails = GetRequestCountByStatus(context, (int)StatusEnum.Approved);
                requestStatusCountDetails.Add(approvedItemDetails);
                var closedItemDetails = GetRequestCountByStatus(context, (int)StatusEnum.Closed);
                requestStatusCountDetails.Add(closedItemDetails);

                //convert status - request count into form required for Chart
                reportDetails.DoughnutChartDetails = new ChartsViewModel()
                {
                    ChartData  = requestStatusCountDetails.Select(s => s.Value).ToList(),
                    ChartLable = requestStatusCountDetails.Select(s => s.Lable).ToList()
                };

                return(reportDetails);
            }
        }
Beispiel #14
0
        /// <summary>
        /// To create new repair request in database
        /// </summary>
        /// <param name="repairRequestDetails">details of request</param>
        public void CreateNewRepairRequest(CreateRequestViewModel repairRequestDetails)
        {
            using (RMSDbContext context = new RMSDbContext())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        var requestDetails = new RepairRequestDetails()
                        {
                            CompanyName     = repairRequestDetails.CompanyName,
                            CreatedBy       = repairRequestDetails.CreatedBy,
                            CreatedOn       = DateTime.Now,
                            CustomerContact = repairRequestDetails.CustomerContact,
                            CustomerName    = repairRequestDetails.CustomerName,
                            ModelNumber     = repairRequestDetails.ModelNumber,
                            ProblemDetails  = repairRequestDetails.ProblemDetails,
                            StatusId        = (int)StatusEnum.Pending,
                            CityId          = repairRequestDetails.CityId,
                            CustomerAddress = repairRequestDetails.CustomerAddress,
                            CustomerPinCode = repairRequestDetails.PinCode,
                            Expense         = Convert.ToDecimal(repairRequestDetails.Expense),
                            StateId         = repairRequestDetails.StateId,
                        };
                        context.RepairRequestDetails.Add(requestDetails);
                        UpdateStatusLog(context, requestDetails.RequestId, requestDetails.StatusId, repairRequestDetails.CreatedBy, null);

                        context.SaveChanges();
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }
        }
Beispiel #15
0
        private DashboardViewModel GetRequestListForDashboar(RMSDbContext context, int pageNumber, int?userId, int?statusId)
        {
            var pageSize    = Constants.ITEMS_PER_PAGE;
            var requestList = context.USP_GetRequestsForDashboard(userId, statusId).
                              Select(s => new RequestDetailsForDashboardViewModel()
            {
                CompanyName  = s.CompanyName,
                CreatedOn    = s.CreatedOn.ToString(Constants.DATE_FORMAT),
                CustomerName = s.CustomerName,
                ModelNumber  = s.ModelNumber,
                RequestId    = s.RequestId,
                Status       = s.StatusName
            }).ToList();

            var dashboardViewModel = new DashboardViewModel()
            {
                RequestsList       = requestList.Skip((pageNumber - 1) * pageSize).Take(pageSize).ToList(),
                TotalRequestsCount = requestList.Count,
                ItemsPerPage       = pageSize
            };

            return(dashboardViewModel);
        }
Beispiel #16
0
 public LogService()
 {
     context = new RMSDbContext();
 }