public JsonResult InsertInkindTransactions(string modelString = "")
        {
            int  returnResult = 0;
            long identityRet  = 0;

            try
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                Inkind model = new Inkind();
                model = serializer.Deserialize <Inkind>(modelString);
                if (Session["UserID"] == null)
                {
                    returnResult = 2;
                    return(Json(returnResult, JsonRequestBehavior.AllowGet));
                }

                if (model.InKindDonarsContact.IsInsert)
                {
                    identityRet = new InKindData().InsertInKindDonors(model.InKindDonarsContact);
                    if (identityRet > 0)
                    {
                        foreach (var item in model.InkindTransactionsList)
                        {
                            item.ParentID = identityRet.ToString();

                            item.InKindAmount = GetAmountByInkindType(item);

                            returnResult = new InKindData().InsertInkindTransactions(item);
                        }
                    }
                }
                else
                {
                    foreach (var item in model.InkindTransactionsList)
                    {
                        item.InKindAmount = GetAmountByInkindType(item);

                        returnResult = new InKindData().InsertInkindTransactions(item);
                    }
                }
                returnResult = (returnResult > 0) ? 1 : returnResult;
                return(Json(returnResult, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                clsError.WriteException(ex);
                return(Json(returnResult, JsonRequestBehavior.AllowGet));
            }
        }
Пример #2
0
        public JsonResult InsertInkindTransactions(string modelString = "", string cameraUploads = null)
        //public JsonResult InsertInkindTransactions(Inkind _inkind)
        {
            int  returnResult = 0;
            long identityRet  = 0;

            try
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                serializer.MaxJsonLength = Int32.MaxValue;
                Inkind model = new Inkind();
                model = serializer.Deserialize <Inkind>(modelString);


                var fileKeys = Request.Files.AllKeys;


                model.InkindTransactionsList[0].InkindAttachmentsList = new List <InkindAttachments>();
                var count = model.InkindTransactionsList.Count;
                if (count == 1)
                {
                    for (int i = 0; i < fileKeys.Length; i++)
                    {
                        model.InkindTransactionsList[0].InkindAttachmentsList.Add(new InkindAttachments
                        {
                            InkindAttachmentFile          = Request.Files[i],
                            InkindAttachmentFileName      = Request.Files[i].FileName,
                            InkindAttachmentFileExtension = Path.GetExtension(Request.Files[i].FileName),
                            InkindAttachmentFileByte      = new BinaryReader(Request.Files[i].InputStream).ReadBytes(Request.Files[i].ContentLength)
                        });
                    }

                    if (!string.IsNullOrEmpty(cameraUploads))
                    {
                        List <SelectListItem> cameraUplodList = serializer.Deserialize <List <SelectListItem> >(cameraUploads);

                        foreach (var item in cameraUplodList)
                        {
                            model.InkindTransactionsList[0].InkindAttachmentsList.Add(new InkindAttachments
                            {
                                //InkindAttachmentFile = Convert.FromBase64String(item.Value),
                                InkindAttachmentFileName      = item.Text,
                                InkindAttachmentFileExtension = ".png",
                                InkindAttachmentFileByte      = Convert.FromBase64String(item.Value)
                            });
                        }
                    }
                }



                if (Session["UserID"] == null)
                {
                    returnResult = 2;
                    return(Json(returnResult, JsonRequestBehavior.AllowGet));
                }

                if (model.InKindDonarsContact.IsInsert)
                {
                    identityRet = new InKindData().InsertInKindDonors(model.InKindDonarsContact);
                    if (identityRet > 0)
                    {
                        foreach (var item in model.InkindTransactionsList)
                        {
                            item.ParentID = identityRet.ToString();

                            item.InKindAmount = GetAmountByInkindType(item);

                            item.CenterID       = (item.CenterID > 0) ? item.CenterID : !string.IsNullOrEmpty(item.Enc_CenterID) ? Convert.ToInt32(EncryptDecrypt.Decrypt64(item.Enc_CenterID)) : item.CenterID;
                            item.ClassroomID    = (item.ClassroomID > 0) ? item.ClassroomID : !string.IsNullOrEmpty(item.Enc_ClassroomID) ? Convert.ToInt32(EncryptDecrypt.Decrypt64(item.Enc_ClassroomID)) : item.ClassroomID;
                            item.IsActive       = true;
                            item.StaffSignature = item.StaffSignature ?? new StaffSignature();
                            returnResult        = new InKindData().InsertInkindTransactions(item);
                        }
                    }
                }
                else
                {
                    foreach (var item in model.InkindTransactionsList)
                    {
                        item.InKindAmount = GetAmountByInkindType(item);


                        item.CenterID    = (item.CenterID > 0) ? item.CenterID : !string.IsNullOrEmpty(item.Enc_CenterID) ? Convert.ToInt32(EncryptDecrypt.Decrypt64(item.Enc_CenterID)) : item.CenterID;
                        item.ClassroomID = (item.ClassroomID > 0) ? item.ClassroomID : !string.IsNullOrEmpty(item.Enc_ClassroomID) ? Convert.ToInt32(EncryptDecrypt.Decrypt64(item.Enc_ClassroomID)) : item.ClassroomID;

                        item.IsActive       = true;
                        item.StaffSignature = item.StaffSignature ?? new StaffSignature();
                        returnResult        = new InKindData().InsertInkindTransactions(item);
                    }
                }
                returnResult = (returnResult > 0) ? 1 : returnResult;
                return(Json(returnResult, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                clsError.WriteException(ex);
                return(Json(returnResult, JsonRequestBehavior.AllowGet));
            }
        }