Exemplo n.º 1
0
        public async Task<ActionResult> Create(ProcessResultViewModel model)
        {
            if (ModelState.IsValid)
            {
                MSTProcessResultDto pro = new MSTProcessResultDto()
                {
                    ProcessTypeId = model.ProcessTypeId,
                    Value = model.Value,
                    Description = model.Description,
                    LastUpdatedBy = CurrentName
                };
                var result = await ProcessResultRespository.AddAsync(pro);

                if (result == Model.SaveResult.SUCCESS)
                    return RedirectToAction("Index");
            }

            model.ProcessType = ProcessTypesRepository.GetAll();
            return View(model);
        }
Exemplo n.º 2
0
        public async Task<ActionResult> Edit(int id, ProcessResultViewModel model)
        {
            if (ModelState.IsValid)
            {
                var status = new MSTProcessResultDto()
                {
                    Id = id,
                    ProcessTypeId = model.ProcessTypeId,
                    Value = model.Value,
                    Description = model.Description,
                    LastUpdatedBy = CurrentName,
                };
                var result = await ProcessResultRespository.UpdateAsync(status);

                if (result == Model.SaveResult.SUCCESS)
                    return RedirectToAction("Index");
            }

            IEnumerable<MSTProcessTypesDto> processType = await ProcessTypesRepository.GetAllAsync();
            model.ProcessType = processType;
            return View(model);
        }
        /// <summary>
        /// Adds the asynchronous.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public async Task<SaveResult> AddAsync(MSTProcessResultDto entity)
        {
            SaveResult result = SaveResult.FAILURE;
            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    MST_ProcessResult add = context.MST_ProcessResult.Create();

                    add.ProcessTypeId = entity.ProcessTypeId;
                    add.Value = entity.Value;
                    add.Description = entity.Description;
                    add.IsDeleted = entity.IsDeleted;
                    add.LastUpdatedBy = entity.LastUpdatedBy;
                    add.LastUpdate = DateTime.Now;

                    context.Entry<MST_ProcessResult>(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;
        }
        /// <summary>
        /// Deletes the asynchronous.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public async Task<SaveResult> DeleteAsync(MSTProcessResultDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

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

                    context.Entry<MST_ProcessResult>(del).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;
        }
        /// <summary>
        /// Updates the asynchronous.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public async Task<SaveResult> UpdateAsync(MSTProcessResultDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

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

                    update.ProcessTypeId = entity.ProcessTypeId;
                    update.Value = entity.Value;
                    update.Description = entity.Description;
                    update.LastUpdatedBy = entity.LastUpdatedBy;
                    update.LastUpdate = DateTime.Now;

                    context.Entry<MST_ProcessResult>(update).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;
        }