Ejemplo n.º 1
0
        public ContentResult ManAttachReport(int id, string type, int ReasonId)
        {
            string saveFolder = Path.Combine(Server.MapPath("~/Upload"), id.ToString().PadLeft(10, '0'), type);
            if (!Directory.Exists(saveFolder))
                Directory.CreateDirectory(saveFolder);
            //Remove all file in folder saveFolder
            string[] files = Directory.GetFiles(saveFolder);
            foreach (string file in files)
                System.IO.File.Delete(file);
            foreach (string file in Request.Files)
            {
                HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
                if (hpf.ContentLength == 0)
                    continue;

                string savedFileName = Path.Combine(saveFolder, Path.GetFileName(hpf.FileName));
                hpf.SaveAs(savedFileName); // Save the file

                //Log history upload file
                FARUploadDto uploadFile = new FARUploadDto
                {
                    FAType = type,
                    FileName = hpf.FileName,
                    MasterId = id,
                    UploadedBy = this.CurrentName,
                    ReasonId = ReasonId
                };
                UploadRep.Add(uploadFile);
            }
            // Returns json
            files = Directory.GetFiles(saveFolder);
            string json = string.Empty;
            foreach (string file in files)
            {
                json += "<a href=" + Url.Action("Download", new { id = id, file = Path.GetFileName(file), type = type }) + ">" + Path.GetFileName(file) + "</a>" + "<br/>";
            }
            return Content(json, "application/html");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds the asynchronous.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public async Task<SaveResult> AddAsync(FARUploadDto entity)
        {
            SaveResult result = SaveResult.FAILURE;
            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    LOG_FARUpload add = context.LOG_FARUpload.Create();
                    add.FileName = entity.FileName;
                    add.MasterId = entity.MasterId;
                    add.ReasonId = entity.ReasonId;
                    add.FAType = entity.FAType;
                    add.UploadedBy = entity.UploadedBy;
                    add.UploadedDate = DateTime.Now;

                    context.Entry<LOG_FARUpload>(add).State = System.Data.Entity.EntityState.Added;
                    result = await context.SaveChangesAsync() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }
            return result;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Deletes the asynchronous.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public async Task<SaveResult> DeleteAsync(FARUploadDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    var assembly = context.LOG_FARUpload.Single(x => x.Id == entity.Id);

                    context.Entry<LOG_FARUpload>(assembly).State = System.Data.Entity.EntityState.Deleted;
                    result = await context.SaveChangesAsync() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }

            return result;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Updates the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public SaveResult Update(FARUploadDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    var upload = context.LOG_FARUpload.Single(x => x.Id == entity.Id);

                    upload.FileName = entity.FileName;
                    upload.MasterId = entity.MasterId;
                    upload.ReasonId = entity.ReasonId;
                    upload.FAType = entity.FAType;
                    upload.UploadedBy = entity.UploadedBy;
                    upload.UploadedDate = DateTime.Now;

                    context.Entry<LOG_FARUpload>(upload).State = System.Data.Entity.EntityState.Modified;
                    result = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }

            return result;
        }