/// <summary>
        /// Deletes the asynchronous.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public async Task<SaveResult> DeleteAsync(MSTProcessProductDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

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

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

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

                    update.InChargePerson = entity.InChargePerson;
                    update.IsDeleted = entity.IsDeleted;
                    update.Description = entity.Description;
                    update.LastUpdatedBy = entity.LastUpdatedBy;
                    update.LastUpdate = DateTime.Now;

                    context.Entry<MST_ProcessProduct>(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;
        }
        /// <summary>
        /// Adds the asynchronous.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public async Task<SaveResult> AddAsync(MSTProcessProductDto entity)
        {
            SaveResult result = SaveResult.FAILURE;
            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    MST_ProcessProduct add = context.MST_ProcessProduct.Create();

                    //Check productId and ProcessTypeId exits record?
                    var checkExits = context.MST_ProcessProduct.Where(x => x.ProcessTypeId == entity.ProcessTypeId && x.ProductId == entity.ProductId).FirstOrDefault();
                    if (checkExits != null)
                    {
                        checkExits.InChargePerson = entity.InChargePerson;
                        checkExits.IsDeleted = false;
                        checkExits.LastUpdatedBy = entity.LastUpdatedBy;
                        checkExits.LastUpdate = DateTime.Now;

                        context.Entry<MST_ProcessProduct>(checkExits).State = System.Data.Entity.EntityState.Modified;
                    }
                    else
                    {
                        add.Description = entity.Description;
                        add.ProductId = entity.ProductId;
                        add.ProcessTypeId = entity.ProcessTypeId;
                        add.InChargePerson = entity.InChargePerson;
                        add.IsDeleted = false;
                        add.LastUpdatedBy = entity.LastUpdatedBy;
                        add.LastUpdate = DateTime.Now;

                        context.Entry<MST_ProcessProduct>(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;
        }
        public async Task<ActionResult> Create(ProcessProductViewModel viewmodel)
        {
            if (ModelState.IsValid)
            {
                MSTProcessProductDto bu = new MSTProcessProductDto
                {
                    ProcessTypeId = viewmodel.ProcessId,
                    ProductId = viewmodel.ProductId,
                    InChargePerson = viewmodel.InChargePerson,
                    Description = viewmodel.Description,
                    LastUpdatedBy = CurrentName
                };
                var result = await ProProtRep.AddAsync(bu);

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

            return View(viewmodel);
        }