public OverAllSummaryOfWeekDetailsMainModel GetSummaryMain(GetSummaryModel model)
        {
            var serialized = new JavaScriptSerializer().Serialize(model);
            var client     = new HttpClient();
            var content    = new StringContent(serialized, System.Text.Encoding.UTF8, "application/json");

            client.BaseAddress = new Uri(HttpContext.Request.Url.AbsoluteUri);
            var result = client.PostAsync(BaseURL + "/api/Employee/SummaryOfWeekDetails", content).Result;

            if (result.StatusCode == HttpStatusCode.OK)
            {
                var contents = result.Content.ReadAsStringAsync().Result;
                var Response = new JavaScriptSerializer().Deserialize <OverAllSummaryOfWeekDetailsMainModel>(contents);
                return(Response);
            }
            return(null);
        }
Beispiel #2
0
        public async Task <IActionResult> GetSummary([FromBody] GetSummaryModel data)
        {
            if (data == null || !ModelState.IsValid)
            {
                return(BadRequest(new ErrorModel <object>(ProjectCodes.Form_Generic_Error)));
            }

            try {
                data.FromDate = TimeZoneInfo.ConvertTimeToUtc(data.FromDate);
                data.ToDate   = TimeZoneInfo.ConvertTimeToUtc(data.ToDate);

                var summaryModel = new SummaryModel()
                {
                    TotalExpenditure       = 0,
                    ExpenditureCategoryMap = new Dictionary <string, SpendingCategoryModel>()
                };

                var expenses = await _expenseRepository.GetAllExpenses(data.UserId, data.FromDate, data.ToDate);

                expenses.ForEach(exp => {
                    int categoryId;
                    ExpenseCategory category = null;
                    if (exp.ExpenseCategory.ParentId != null)
                    {
                        categoryId = exp.ExpenseCategory.ParentId.Value;
                        category   = exp.ExpenseCategory.ExpenseCategoryParent;
                    }
                    else
                    {
                        categoryId = exp.ExpenseCategory.ExpenseCategoryId;
                        category   = exp.ExpenseCategory;
                    }

                    if (summaryModel.ExpenditureCategoryMap.ContainsKey(categoryId.ToString()))
                    {
                        summaryModel.ExpenditureCategoryMap[categoryId.ToString()].CategoryExpenditure += exp.Price;
                    }
                    else
                    {
                        summaryModel.ExpenditureCategoryMap.Add(categoryId.ToString(), new SpendingCategoryModel()
                        {
                            CategoryExpenditure = exp.Price,
                            ExpenseCategory     = new ExpenseCategory()
                            {
                                ExpenseCategoryId = category.ExpenseCategoryId,
                                Name            = category.Name,
                                ParentId        = category.ParentId,
                                ChildCategories = null,
                                UserId          = category.UserId
                            }
                        });
                    }

                    summaryModel.TotalExpenditure += exp.Price;
                });

                return(Ok(summaryModel));
            }
            catch (Exception e) {
                return(BadRequest(new ErrorModel <object>(ProjectCodes.Generic_Error)));
            }
        }