public Gender Post(Gender gender) { var item = gender.GetDataObject(); using (var dbContext = new SMSEntities()) { if (item.Id == 0) { if (!IsAlreadyExist(item.Name)) { dbContext.genders.Add(item); dbContext.SaveChanges(); } } else { dbContext.Entry(item).State = EntityState.Modified; dbContext.SaveChanges(); } } gender.Id = item.Id; return(gender); }