Esempio n. 1
0
        public static BudgetDetail GetBudget(string accessToken, string userId)
        {
            AWSSDKHandler.RegisterXRayForAllServices();
            AWSXRayRecorder.Instance.BeginSubsegment("MyBudgetExplorer.Models.Cache.GetBudget()");
            try
            {
                // Local File
                BudgetDetail budget = GetLocalBudget(userId);
                if (budget != null)
                {
                    return(budget);
                }

                // S3 File
                budget = GetS3Budget(userId);
                if (budget != null)
                {
                    return(budget);
                }

                // API File
                budget = GetApiBudget(accessToken, userId);

                return(budget);
            }
            catch (Exception e)
            {
                AWSXRayRecorder.Instance.AddException(e);
                throw;
            }
            finally
            {
                AWSXRayRecorder.Instance.EndSubsegment();
            }
        }
 public async Task <UpsertBaseBudgetDetailResponse> UpsertBaseBudgetDetailAsync(UpsertBaseBudgetDetailRequest request)
 {
     return(await Task.Run(() =>
     {
         UpsertBaseBudgetDetailResponse _response = new UpsertBaseBudgetDetailResponse();
         using (AsyncAutomateAccountingEntities _dbContext = new AsyncAutomateAccountingEntities())
         {
             if (request.BaseObject != null)
             {
                 try
                 {
                     BudgetDetail _BudgetDetail = request.BaseObject.ToBudgetDetail();
                     UpsertEntity <BudgetDetail>(request.BaseObject.Id, ref _BudgetDetail, _dbContext);
                     _response.BaseObject = _BudgetDetail.ToBaseBudgetDetail();
                 }
                 catch (Exception ex) { AssignStatusData(_response, false, string.Format("Some error occurred during DB interaction. Message is something like : \n{0}", ex.Message)); }
             }
             else
             {
                 AssignStatusData(_response, false, "No entity data recieved to insert/update.");
             }
         }
         return _response;
     }));
 }
Esempio n. 3
0
        public static BaseBudgetDetailModel ToBaseBudgetDetail(this BudgetDetail budgetDetail)
        {
            BaseBudgetDetailModel _result = new BaseBudgetDetailModel();

            _result.BudgetMasterId = budgetDetail.BudgetMasterId;
            _result.Particular     = budgetDetail.Particular;
            _result.ExtraDate      = budgetDetail.ExtraDate;
            _result.Credit         = budgetDetail.Credit;
            _result.Debit          = budgetDetail.Debit;
            _result.CreatedDate    = budgetDetail.CreatedDate;
            _result.ModifiedDate   = budgetDetail.ModifiedDate;
            return(_result);
        }
Esempio n. 4
0
        internal static ExpenseTransaction CreateNewExpense(BudgetDetail budgetCategory, string description, decimal expendedValue, DateTime transactionDate)
        {
            var newExpense = new ExpenseTransaction
            {
                BudgetCategoryId = budgetCategory.UId,
                BudgetCategory   = budgetCategory,
                Description      = description,
                Value            = expendedValue,
                TransactionDate  = transactionDate,
            };

            budgetCategory.AddExpense(newExpense);
            return(newExpense);
        }
Esempio n. 5
0
        public static BudgetDetail ToBudgetDetail(this BaseBudgetDetailModel budgetDetail)
        {
            BudgetDetail _result = new BudgetDetail();

            if (budgetDetail.Id.HasValue)
            {
                _result.Id = budgetDetail.Id.GetValueOrDefault();
            }
            _result.BudgetMasterId = budgetDetail.BudgetMasterId;
            _result.Particular     = budgetDetail.Particular;
            _result.ExtraDate      = budgetDetail.ExtraDate;
            _result.Credit         = budgetDetail.Credit;
            _result.Debit          = budgetDetail.Debit;
            _result.CreatedDate    = budgetDetail.CreatedDate;
            _result.ModifiedDate   = budgetDetail.ModifiedDate;
            return(_result);
        }
Esempio n. 6
0
 public CreateTransaction(API api)
 {
     _ynabApi     = api;
     _testBudget  = _ynabApi.Budgets.GetBudgetById("14235236-8085-4cf6-9fa6-92c34ed44b0c").Data.Budget;
     _transaction = new SaveTransaction
     {
         AccountId  = _testBudget.Accounts.First().Id,
         Amount     = 100L,
         Date       = DateTime.Now,
         PayeeId    = _testBudget.Payees.First().Id,
         PayeeName  = _testBudget.Payees.First().Name,
         CategoryId = _testBudget.Categories.First().Id,
         Memo       = "Test Transaction",
         Approved   = true,
         Cleared    = SaveTransaction.ClearedEnum.Cleared,
         FlagColor  = SaveTransaction.FlagColorEnum.Red
     };
 }
Esempio n. 7
0
 public int CreateBudgetDetail(beBudgetDetail budgetDetailEntity)
 {
     using (var scope = new TransactionScope())
     {
         var budgetDetail = new BudgetDetail
         {
             Id         = new int(),
             BudgetId   = budgetDetailEntity.BudgetId,
             Amount     = budgetDetailEntity.Amount,
             CategoryId = budgetDetailEntity.CategoryId,
             CreatedBy  = budgetDetailEntity.CreatedBy,
             CreatedOn  = DateTime.Now,
             ModifiedBy = budgetDetailEntity.ModifiedBy,
             ModifiedOn = budgetDetailEntity.ModifiedOn,
         };
         _unitOfWork.BudgetDetailRepository.Insert(budgetDetail);
         _unitOfWork.Save();
         scope.Complete();
         return(budgetDetail.Id);
     }
 }
Esempio n. 8
0
        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            //Button Name   : btnSearch_Click
            //Purpose       : calls for method GetBudgetDetail() to check if budget exists
            //Input         : budgetId
            //Output        : budget
            bool hasValues = HasValues();

            if (hasValues)
            {
                bool isNum = IsNumber();
                if (isNum)
                {
                    string budgetId = txtBudgetId.Text;
                    budgetDetail = myBudgetProxy.GetBudgetDetail(budgetId);
                    if (budgetDetail != null)
                    {
                        txtBudgetItem.Text      = budgetDetail.budgetItem.ToString();
                        txtBudgetItemPrice.Text = budgetDetail.budgetPrice.ToString();
                        txtStudentId.Text       = budgetDetail.studentId.ToString();
                    }
                    else
                    {
                        MessageBox.Show("note does not exist", "INFORMATION", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
                else
                {
                    MessageBox.Show("make sure budget ID is a number!", "INFORMATION", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            else
            {
                MessageBox.Show("Please enter Id.", "INFORMATION", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            txtBudgetId.IsEnabled        = false;
            txtBudgetItem.IsEnabled      = true;
            txtBudgetItemPrice.IsEnabled = true;
            txtStudentId.IsEnabled       = false;
        }
Esempio n. 9
0
        public static BudgetDetail GetLocalBudget(string userId)
        {
            AWSXRayRecorder.Instance.BeginSubsegment("MyBudgetExplorer.Models.Cache.GetLocalBudget()");
            try
            {
                var binaryFormatter = new BinaryFormatter();
                var aesKey          = SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(userId));
                var aesIV           = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(userId));
                var hash            = BitConverter.ToString(aesKey).Replace("-", "").ToLower();
                var fileName        = $"budget.{hash}";
                var tempFilePath    = Path.Combine(Path.GetTempPath(), fileName);

                BudgetDetail budget = null;
                if (File.Exists(tempFilePath))
                {
                    try
                    {
                        var decrypted = DecryptAES(File.ReadAllBytes(tempFilePath), aesKey, aesIV);
                        using (var ms = new MemoryStream(decrypted))
                        {
                            budget = (BudgetDetail)binaryFormatter.Deserialize(ms);
                        }
                    }
                    catch
                    {
                        AWSXRayRecorder.Instance.AddAnnotation("Budget-Local-Cache", "File found, deserialize failed.");
                        File.Delete(tempFilePath);
                    }
                }


                return(budget);
            }
            finally
            {
                AWSXRayRecorder.Instance.EndSubsegment();
            }
        }
Esempio n. 10
0
        public static Response NewBudget(NewBudgetView newBudget, string userName)
        {
            using (var transacction = db.Database.BeginTransaction())
            {
                try
                {
                    var user = db.Users.FirstOrDefault(u => u.UserName == userName);
                    int companyId;
                    var adminUser = WebConfigurationManager.AppSettings["AdminUser"];
                    if (adminUser == userName)
                    {
                        companyId = newBudget.CompanyId;
                    }
                    else
                    {
                        companyId = user.CompanyId;
                    }

                    var budget = new Budget
                    {
                        CompanyId   = companyId,
                        CustomerId  = newBudget.CustomerId,
                        ProjectId   = newBudget.ProjectId,
                        Date        = newBudget.Date,
                        Remarks     = newBudget.Remarks,
                        TotalButget = newBudget.TotalButget,
                    };
                    db.Budgets.Add(budget);
                    db.SaveChanges();

                    var details = db.BudgetDetailTmps.Where(odt => odt.UserName == userName).ToList();
                    foreach (var budgetDetailTmp in details)
                    {
                        var budgetDetail = new BudgetDetail
                        {
                            Description     = budgetDetailTmp.Description,
                            BudgetId        = budget.BudgetId,
                            Category        = budgetDetailTmp.Category,
                            CategoryCode    = budgetDetailTmp.CategoryCode,
                            Subcategory     = budgetDetailTmp.Subcategory,
                            SubcategoryCode = budgetDetailTmp.SubcategoryCode,
                            Metered         = budgetDetailTmp.Metered,
                            Unity           = budgetDetailTmp.Unity,
                            UnitPrice       = budgetDetailTmp.UnitPrice,
                            PartialPrice    = budgetDetailTmp.PartialPrice,
                            Remarks         = budgetDetailTmp.Remarks,
                        };

                        db.BudgetDetails.Add(budgetDetail);
                        db.BudgetDetailTmps.Remove(budgetDetailTmp);
                    }
                    db.SaveChanges();

                    var budgetEdit = db.Budgets.FirstOrDefault(odt => odt.BudgetId == budget.BudgetId);
                    budgetEdit.TotalButget     = db.BudgetDetails.Where(odt => odt.BudgetId == budget.BudgetId).Sum(a => a.PartialPrice);
                    db.Entry(budgetEdit).State = EntityState.Modified;

                    db.SaveChanges();
                    transacction.Commit();
                    return(new Response {
                        Succeeded = true
                    });
                }
                catch (Exception ex)
                {
                    transacction.Rollback();
                    return(new Response {
                        Message = ex.Message, Succeeded = false
                    });
                }
            }
        }
Esempio n. 11
0
        public static BudgetDetail GetApiBudget(string accessToken, string userId)
        {
            AWSSDKHandler.RegisterXRayForAllServices();
            AWSXRayRecorder.Instance.BeginSubsegment("MyBudgetExplorer.Models.Cache.GetApiBudget()");
            try
            {
                var binaryFormatter = new BinaryFormatter();
                var aesKey          = SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(userId));
                var aesIV           = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(userId));
                var hash            = BitConverter.ToString(aesKey).Replace("-", "").ToLower();
                var fileName        = $"budget.{hash}";
                var tempFilePath    = Path.Combine(Path.GetTempPath(), fileName);

                BudgetDetail budget    = null;
                byte[]       encrypted = null;

                var api        = new YnabApi(accessToken);
                var tempBudget = api.GetBudget();
                budget = tempBudget.Data.Budget;
                budget.LastModifiedOn = DateTime.UtcNow;

                using (var ms = new MemoryStream())
                {
                    binaryFormatter.Serialize(ms, budget);
                    encrypted = EncryptAES(ms.ToArray(), aesKey, aesIV);
                }

                // Store S3 File
                if (!string.IsNullOrWhiteSpace(awsAccessKey) && !string.IsNullOrWhiteSpace(awsSecretKey))
                {
                    using (IAmazonS3 client = new AmazonS3Client(awsAccessKey, awsSecretKey, RegionEndpoint.USEast2))
                    {
                        using (var ms = new MemoryStream(encrypted))
                        {
                            var putrequest = new PutObjectRequest
                            {
                                BucketName  = bucketName,
                                Key         = fileName,
                                InputStream = ms
                            };

                            client.PutObjectAsync(putrequest).Wait();
                        }
                    }
                }

                // Store Local File
                if (encrypted != null && encrypted.Length > 0)
                {
                    File.WriteAllBytes(tempFilePath, encrypted);
                    File.SetCreationTimeUtc(tempFilePath, budget.LastModifiedOn);
                    File.SetLastWriteTimeUtc(tempFilePath, budget.LastModifiedOn);
                }

                return(budget);
            }
            finally
            {
                AWSXRayRecorder.Instance.EndSubsegment();
            }
        }
Esempio n. 12
0
        public static BudgetDetail GetS3Budget(string userId)
        {
            AWSSDKHandler.RegisterXRayForAllServices();
            AWSXRayRecorder.Instance.BeginSubsegment("MyBudgetExplorer.Models.Cache.GetS3Budget()");
            try
            {
                if (string.IsNullOrWhiteSpace(awsAccessKey) || string.IsNullOrWhiteSpace(awsSecretKey))
                {
                    return(null);
                }

                var binaryFormatter = new BinaryFormatter();
                var aesKey          = SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(userId));
                var aesIV           = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(userId));
                var hash            = BitConverter.ToString(aesKey).Replace("-", "").ToLower();
                var fileName        = $"budget.{hash}";
                var tempFilePath    = Path.Combine(Path.GetTempPath(), fileName);

                BudgetDetail budget = null;
                using (IAmazonS3 client = new AmazonS3Client(awsAccessKey, awsSecretKey, RegionEndpoint.USEast2))
                {
                    byte[]           encrypted = null;
                    GetObjectRequest request   = new GetObjectRequest
                    {
                        BucketName = bucketName,
                        Key        = fileName
                    };
                    try
                    {
                        using (GetObjectResponse response = client.GetObjectAsync(request).Result)
                        {
                            byte[] buffer = new byte[128 * 1024];
                            using (MemoryStream ms = new MemoryStream())
                            {
                                int read;
                                while ((read = response.ResponseStream.Read(buffer, 0, buffer.Length)) > 0)
                                {
                                    ms.Write(buffer, 0, read);
                                }
                                encrypted = ms.ToArray();
                            }
                        }

                        var decrypted = DecryptAES(encrypted, aesKey, aesIV);
                        using (var ms = new MemoryStream(decrypted))
                        {
                            budget = (BudgetDetail)binaryFormatter.Deserialize(ms);
                        }

                        if (encrypted != null && encrypted.Length > 0)
                        {
                            File.WriteAllBytes(tempFilePath, encrypted);
                            File.SetCreationTimeUtc(tempFilePath, budget.LastModifiedOn);
                            File.SetLastWriteTimeUtc(tempFilePath, budget.LastModifiedOn);
                        }
                    }
                    catch
                    {
                    }

                    return(budget);
                }
            }
            finally
            {
                AWSXRayRecorder.Instance.EndSubsegment();
            }
        }
Esempio n. 13
0
 public Task <Budget> EditBudgetDetailAsync(BudgetDetail budgetDetail)
 {
     throw new NotImplementedException();
 }