public FileResult Export(WorkerFilter filter)
        {
            var response = _workerService.Filter(filter);
            var branches = _branchService.Filter(new BranchFilter()).Branches;

            var csv = new CsvExport();

            if (filter.IsReport)
            {
                csv.ConcatRow(0, "COMPAÑÍA,ID SUCURSAL,SUCURSAL,DEPARTAMENTO,PUESTO,CÓDIGO,NOMBRE,GÉNERO,NSS,FECHA CONSUMO,CONSUMIDO,RECOMENDADO");
                foreach (var worker in response.Workers)
                {
                    var today            = DateTimeExtensions.Today();
                    var startDate        = filter.Month.IsGreaterThanZero() ? new DateTime(today.Year, today.Month, 1).ConvertToString() : "";
                    var endDate          = filter.Month.IsGreaterThanZero() ? new DateTime(today.Year, today.Month, DateTime.DaysInMonth(today.Year, today.Month)).ConvertToString() : "";;
                    var responseCalories = _reservationService.Report(new ReservationReport {
                        WorkerId = worker.Id, StartDate = startDate, EndDate = endDate
                    });
                    var currentCompany = branches.First(branch => branch.Id.IsEqualTo(worker.BranchId)).Company.Name;
                    //var responseCalories = new ReservationReportResponse
                    //{
                    //    Calories = new List<ReservationCalorieReportResponse>
                    //{
                    //    new ReservationCalorieReportResponse{Date = DateTimeExtensions.Today().AddDays(-7).ConvertToString(),Dinner = 200, Lunch = 1000, BreakFast = 150},
                    //    new ReservationCalorieReportResponse{Date = DateTimeExtensions.Today().AddDays(-6).ConvertToString(),Dinner = 164, Lunch = 1000, BreakFast = 150},
                    //    new ReservationCalorieReportResponse{Date = DateTimeExtensions.Today().AddDays(-5).ConvertToString(),Dinner = 195, Lunch = 1000, BreakFast = 150},
                    //    new ReservationCalorieReportResponse{Date = DateTimeExtensions.Today().AddDays(-4).ConvertToString(),Dinner = 109, Lunch = 1000, BreakFast = 203},
                    //    new ReservationCalorieReportResponse{Date = DateTimeExtensions.Today().AddDays(-3).ConvertToString(),Dinner = 287, Lunch = 1000, BreakFast = 343},
                    //    new ReservationCalorieReportResponse{Date = DateTimeExtensions.Today().AddDays(-2).ConvertToString(),Dinner = 207, Lunch = 1000, BreakFast = 150},
                    //    new ReservationCalorieReportResponse{Date = DateTimeExtensions.Today().AddDays(-1).ConvertToString(),Dinner = 218, Lunch = 1000, BreakFast = 145}
                    //}
                    //};
                    foreach (var calorie in responseCalories.Calories)
                    {
                        var sumCalories = calorie.BreakFast + calorie.Dinner + calorie.Lunch;
                        var row         = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11}", currentCompany, worker.BranchId, worker.Branch.Name, worker.Department.Name, worker.Job.Name, worker.Code, worker.FullName, EnumResolver.Gender(worker.Gender.GetValue()), worker.Imss, calorie.Date, sumCalories.RoundDecimal(), worker.LimitEnergy);
                        csv.ConcatRow(0, row);
                    }
                }
            }
            else
            {
                csv.ConcatRow(0, "CÓDIGO,NOMBRE,APELLIDO,EMAIL,IMSS,GÉNERO,GAFFETE,INGESTA CALÓRICA,SUCURSAL,DEPARTAMENTO,PUESTO,ROL,ESTADO");
                csv.ConcatRows(0, "Code,FirstName,LastName,Email,Imss,GenderLabel,Badge,LimitEnergy,Branch,Department,Job,Role,Status", response.Workers);
            }

            var stream = csv.RetrieveFile();

            return(new StreamFactory().Csv(stream, "Ingesta calórica por colaborador"));
        }
Пример #2
0
        private static string ExtractValue <T>(string property, T objectRetrieved)
        {
            property = property.Trim();
            var valueRetrieved = objectRetrieved.ExtractProperty(property);
            var valueString    = String.Empty;

            if (valueRetrieved.IsNotNull())
            {
                switch (property)
                {
                case "Region":
                case "Company":
                case "Branch":
                case "Disease":
                case "IngredientGroup":
                case "Dealer":
                case "Department":
                case "Job":
                case "Saucer":
                case "Role":
                    valueString = valueRetrieved.ExtractName();
                    break;

                case "Protein":
                case "Carbohydrate":
                case "Sugar":
                case "Lipid":
                case "Sodium":
                case "NetWeight":
                    valueString = String.Format("{0}{1}", valueRetrieved, DisplayConstants.Gram);
                    break;

                case "Badge":
                case "Code":
                case "Imss":
                    valueString = String.Format(" [{0}] ", valueRetrieved);
                    break;

                case "Saucers":
                case "Dealers":
                    valueString = valueRetrieved.ExtractNames();
                    break;

                case "Energy":
                case "LimitEnergy":
                    valueString = String.Format("{0} {1}", valueRetrieved, DisplayConstants.KiloCalorie);
                    break;

                case "Status":
                    valueString = EnumResolver.Status(Convert.ToBoolean(valueRetrieved));
                    break;

                case "Gender":
                    valueString = EnumResolver.Gender(GenderType.Male.GetValue());
                    break;

                case "SaucerConfigurations":
                    valueString = valueRetrieved.ExtractTotalAmounts();
                    break;

                case "SaucerMultimedias":
                    valueString = valueRetrieved.ExtractPaths();
                    break;

                default:
                    valueString = valueRetrieved.ToString();
                    break;
                }
            }

            return(valueString.Replace(",", " "));
        }