/// <summary> /// Adding or Updating Position in a database /// </summary> /// <param name="position">Business Object Position</param> /// <returns>True if succeeded and false otherwise</returns> public async Task <bool> SavePosition(DtoPosition position) { try { using (var data = Context) { var p = await (from item in data.Position where position.Id == item.id select item).FirstOrDefaultAsync(); // Updating Position if (p != null) { p.name = position.Name; p.description = position.Description; } // Adding new Position else { if (await(from item in data.Position where position.Name == item.name select item).AnyAsync()) { return(false); } data.Position.Add(PositionConverter.DtoToDataAccess(position)); } await data.SaveChangesAsync(); } return(true); } catch (Exception) { return(false); } }