public async Task <Guid> Save(SecurityQuestionDTO _Dto, Guid Id, int EntityState) { SecurityQuestionMaster _SecurityQuestionMaster = new SecurityQuestionMaster(); if (_Dto != null) { _SecurityQuestionMaster.Id = Id; _SecurityQuestionMaster.Question = _Dto.Question; _SecurityQuestionMaster.Description = _Dto.Description; _SecurityQuestionMaster.StatusCode = EMPConstants.Active; } if (_Dto.Id != null) { _SecurityQuestionMaster.CreatedBy = _Dto.UserId; _SecurityQuestionMaster.CreatedDate = DateTime.Now; _SecurityQuestionMaster.LastUpdatedBy = _Dto.UserId; _SecurityQuestionMaster.LastUpdatedDate = DateTime.Now; } else { _SecurityQuestionMaster.LastUpdatedBy = _Dto.UserId; _SecurityQuestionMaster.LastUpdatedDate = DateTime.Now; } if (EntityState == (int)System.Data.Entity.EntityState.Modified) { db.Entry(_SecurityQuestionMaster).State = System.Data.Entity.EntityState.Modified; } else { db.SecurityQuestionMasters.Add(_SecurityQuestionMaster); } try { await db.SaveChangesAsync(); return(_SecurityQuestionMaster.Id); } catch (DbUpdateConcurrencyException) { if (!IsExists(_SecurityQuestionMaster.Id)) { return(_SecurityQuestionMaster.Id); } else { throw; } } }
public async Task <Guid> SaveStatus(SecurityQuestionDTO _Dto, Guid Id, int EntityState) { SecurityQuestionMaster SecurityQuestion = new SecurityQuestionMaster(); SecurityQuestion = await db.SecurityQuestionMasters.Where(o => o.Id == Id).FirstOrDefaultAsync(); if (SecurityQuestion.StatusCode == EMPConstants.InActive) { SecurityQuestion.StatusCode = EMPConstants.Active; } else if (SecurityQuestion.StatusCode == EMPConstants.Active) { SecurityQuestion.StatusCode = EMPConstants.InActive; } if (EntityState == (int)System.Data.Entity.EntityState.Modified) { SecurityQuestion.LastUpdatedDate = DateTime.Now; SecurityQuestion.LastUpdatedBy = _Dto.UserId; db.Entry(SecurityQuestion).State = System.Data.Entity.EntityState.Modified; } try { await db.SaveChangesAsync(); db.Dispose(); return(SecurityQuestion.Id); } catch (DbUpdateConcurrencyException) { if (!IsExists(SecurityQuestion.Id)) { return(Guid.Empty); } else { throw; } } }