Exemplo n.º 1
0
        public ContentResult DeleteImage(string id)
        {
            var iid = id.Substring(1).ToInt();
            var img = CurrentImageDatabase.Images.SingleOrDefault(m => m.Id == iid);

            if (img == null)
            {
                return(Content("#r0"));
            }

            CurrentImageDatabase.Images.DeleteOnSubmit(img);
            CurrentImageDatabase.SubmitChanges();
            return(Content("#r" + iid));
        }
Exemplo n.º 2
0
        public ActionResult Upload(string data)
        {
            CheckScanAuthentication authentication = new CheckScanAuthentication();

            authentication.authenticate();

            if (authentication.hasError())
            {
                return(CheckScanMessage.createLoginErrorReturn(authentication));
            }

            User user = authentication.getUser();

            if (!user.InRole("Finance"))
            {
                return(CheckScanMessage.createErrorReturn("Finance role is required for check scanning"));
            }

            CheckInMessage message = CheckInMessage.createFromString(data);

            List <CheckScanEntry> entries = JsonConvert.DeserializeObject <List <CheckScanEntry> >(message.data);

            BundleHeader header;

            if (message.id == 0)
            {
                header = new BundleHeader
                {
                    BundleHeaderTypeId = 1,
                    BundleStatusId     = BundleStatusCode.Open,
                    CreatedBy          = user.UserId,
                    ContributionDate   = DateTime.Now,
                    CreatedDate        = DateTime.Now,
                    FundId             = CurrentDatabase.Setting("DefaultFundId", "1").ToInt(),
                    RecordStatus       = false,
                    TotalCash          = 0,
                    TotalChecks        = 0,
                    TotalEnvelopes     = 0,
                    BundleTotal        = 0
                };

                CurrentDatabase.BundleHeaders.InsertOnSubmit(header);
                CurrentDatabase.SubmitChanges();
            }
            else
            {
                header = (from h in CurrentDatabase.BundleHeaders
                          where h.BundleHeaderId == message.id
                          select h).FirstOrDefault();
            }

            CheckScanMessage response = new CheckScanMessage();

            if (header != null)
            {
                foreach (CheckScanEntry entry in entries)
                {
                    Other other = new Other();
                    other.Created = DateTime.Now;
                    other.UserID  = user.UserId;

                    if (entry.front.Length > 0)
                    {
                        other.First = Convert.FromBase64String(entry.front);
                    }

                    if (entry.back.Length > 0)
                    {
                        other.Second = Convert.FromBase64String(entry.back);
                    }
                    CurrentImageDatabase.Others.InsertOnSubmit(other);
                    CurrentImageDatabase.SubmitChanges();

                    var detail = new BundleDetail
                    {
                        BundleHeaderId = header.BundleHeaderId,
                        CreatedBy      = user.UserId,
                        CreatedDate    = DateTime.Now
                    };

                    string bankAccount = entry.routing.Length > 0 && entry.account.Length > 0 ? Util.Encrypt(entry.routing + "|" + entry.account) : "";

                    detail.Contribution = new Contribution
                    {
                        CreatedBy            = user.UserId,
                        CreatedDate          = detail.CreatedDate,
                        FundId               = header.FundId ?? 0,
                        PeopleId             = FindPerson(CurrentDatabase, entry.routing, entry.account),
                        ContributionDate     = header.ContributionDate,
                        ContributionAmount   = decimal.Parse(entry.amount),
                        ContributionStatusId = 0,
                        ContributionTypeId   = 1,
                        ContributionDesc     = entry.notes,
                        CheckNo              = entry.number,
                        BankAccount          = bankAccount,
                        ImageID              = other.Id
                    };

                    header.BundleDetails.Add(detail);

                    CurrentDatabase.SubmitChanges();
                }

                response.setSuccess();
                response.id = header.BundleHeaderId;
            }
            else
            {
                response.setError(1, "Invalid Bundle ID");
            }

            return(response);
        }