public CharityRecordUiModel LoadRecordtoEdit(int trid)
        {
            using (CharityEntities entities = new CharityEntities())
            {
                var result = entities.CharityRecords.Where(x => x.Id == trid).Include(x => x.FileDetails).
                             FirstOrDefault();
                List <FileDetailsUiModel> files = new List <FileDetailsUiModel>();
                foreach (var item in result.FileDetails)
                {
                    FileDetailsUiModel model = new FileDetailsUiModel();
                    model.FileInfo  = item.FileInfo;
                    model.FileName  = item.FileName;
                    model.CharityId = item.CharityId;
                    model.id        = item.Id;
                    files.Add(model);
                }

                var record = new CharityRecordUiModel()
                {
                    Charity     = result.Charity,
                    Currency    = (float)result.Currency,
                    Description = result.Description,
                    id          = result.Id,
                    PlayItFwd   = result.PlayItForward,
                    Title       = result.Title,
                    UserId      = result.UserId,
                    FileDetails = files
                };


                return(record);
            }
        }
Ejemplo n.º 2
0
        private CharityRecordUiModel GetRecordInfo(HttpContext httpContext)
        {
            CharityRecordUiModel model = new CharityRecordUiModel();

            try
            {
                model.Title       = httpContext.Request.Params["Title"];
                model.Description = httpContext.Request.Params["Description"];
                model.Charity     = httpContext.Request.Params["Charity"];

                var b = httpContext.Request.Params["Id"];
                if (httpContext.Request.Params["Id"] != "")
                {
                    model.id = Convert.ToInt64(httpContext.Request.Params["Id"]);
                }
                model.UserId    = User.Identity.GetUserId();
                model.Currency  = float.Parse(httpContext.Request.Params["Amount"], CultureInfo.InvariantCulture.NumberFormat);
                model.PlayItFwd = bool.Parse(httpContext.Request.Params["PlayItFwd"]);
                for (int i = 0; i < httpContext.Request.Files.Count; i++)
                {
                    HttpPostedFile httpPostedFile = httpContext.Request.Files[i];
                    if (httpPostedFile != null)
                    {
                        var    type     = httpPostedFile.ContentType;
                        byte[] fileData = null;
                        using (var binaryReader = new BinaryReader(httpPostedFile.InputStream))
                        {
                            fileData = binaryReader.ReadBytes(httpPostedFile.ContentLength);
                            FileDetailsUiModel fileobj = new FileDetailsUiModel();
                            fileobj.FileInfo = fileData;
                            fileobj.FileName = httpPostedFile.FileName;
                            try
                            {
                                model.FileDetails.Add(fileobj);
                            }
                            catch (Exception ex)
                            {
                            }
                        }

                        if (type != "application/pdf")
                        {
                            throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(model);
        }