public Operation <VoterModel> CreateVoter(VoterModel model) { return(Operation.Create(() => { try { var isExists = _context.Voters.Where(c => c.Email == model.Email /*c.StaffName == model.StaffName &&*//* c.StaffNo == model.StaffNo*/).FirstOrDefault(); if (isExists != null) { throw new Exception("user email already exist"); } var exist = _context.Voters.Where(e => e.StaffNo == model.StaffNo).FirstOrDefault(); if (exist != null) { throw new Exception("user staffno already exist"); } var entity = model.Create(model); _context.Voters.Add(entity); _context.SaveChanges(); } catch (Exception xe) { throw xe; } //model.Validate(); return model; })); }
public Operation <VoterModel> CreateVoter(VoterModel model) { return(Operation.Create(() => { //model.Validate(); var isExists = _context.Voters.Where(c => c.VotName == model.VotName).FirstOrDefault(); if (isExists != null) { throw new Exception("restaurant already exist"); } var entity = model.Create(model); _context.Voters.Add(entity); _context.SaveChanges(); return model; })); }