Ejemplo n.º 1
0
        public async Task<ActionResult> Create(FAReportViewModel report)
        {
            if (ModelState.IsValid)
            {
                MSTFarReportDto data = new MSTFarReportDto
                {
                    OriginId = report.OriginId,
                    ReportTypeId = report.ReportTypeId,
                    Required = report.Required,
                    Description = report.Description,
                    LastUpdatedBy = this.CurrentName,
                };
                var result = await FarReportRepository.AddAsync(data);
                if (result == Model.SaveResult.SUCCESS)
                    return RedirectToAction("Index");
            }

            return View(report);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds the asynchronous.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public async Task<SaveResult> AddAsync(MSTFarReportDto entity)
        {
            SaveResult result = SaveResult.FAILURE;
            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    MST_FARReport add = context.MST_FARReport.Create();

                    add.OriginId = entity.OriginId;
                    add.ReportTypeId = entity.ReportTypeId;
                    add.Required = entity.Required;
                    add.Description = entity.Description;
                    add.IsDeleted = false;
                    add.LastUpdatedBy = entity.LastUpdatedBy;
                    add.LastUpdate = DateTime.Now;

                    context.Entry<MST_FARReport>(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(MSTFarReportDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    var report = context.MST_FARReport.Single(x => x.Id == entity.Id && x.IsDeleted == false);
                    report.IsDeleted = true;

                    context.Entry<MST_FARReport>(report).State = System.Data.Entity.EntityState.Modified;
                    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(MSTFarReportDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    var report = context.MST_FARReport.Single(x => x.Id == entity.Id && x.IsDeleted == false);

                    report.OriginId = entity.OriginId;
                    report.ReportTypeId = entity.ReportTypeId;
                    report.Required = entity.Required;
                    report.Description = entity.Description;
                    report.LastUpdatedBy = entity.LastUpdatedBy;
                    report.LastUpdate = DateTime.Now;

                    context.Entry<MST_FARReport>(report).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;
        }