Ejemplo n.º 1
0
        public async Task <JsonResult> ConfirmUpload(UploadDataModel model)
        {
            if (ModelState.IsValid & model != null)
            {
                var  upload = new UploadEntity(User.Identity.GetUserId(), model.BankId, model.BranchId, 0);
                bool result = false;
                try
                {
                    result = await UploadManager.CreateAsync(upload);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
                if (result)
                {
                    try
                    {
                        foreach (var data in model.PData)
                        {
                            var uploaddata = new UploadDataEntity(upload.Id, data.Narration, data.Amount, data.AccountNumber, data.Debit1Credit0, data.PostingCode, data.TranID, data.TranDate, 0);
                            UploadDataManager.Create(uploaddata);
                        }
                    }
                    catch (Exception ex)
                    {
                        //TODO: implement log
                        UploadDataManager.Delete(upload.Id);
                        UploadManager.Delete(upload);
                        throw new Exception("Upload failed");
                    }
                    var branchDetail = await Helper.GetBranchNameAndCode(upload.BranchId);

                    new EmailSender().SendToBranchOperator(branchDetail["BranchCode"]);
                    return(Json(new { code = "00", message = "Successful" }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    throw new Exception("Upload creation failed");
                }
            }
            throw new Exception("Invalid Data Submitted");
        }